On Fri, 2010-12-03 at 12:03 -0600, Michael Roth wrote:
> +static void va_http_send_handler(void *opaque)
> +{
> + VAHTState *s = &va_state->send_state;
> + enum va_http_status http_status;
> + int fd = va_state->fd;
> + int ret;
> +
> + TRACE("called, fd: %d", fd);
> +
> + switch (s->state) {
Why is there a VA_SEND_START state when it always falls through to
VA_SEND_HDR? Is there any difference between these?
> + case VA_SEND_START:
> + s->state = VA_SEND_HDR;
> + case VA_SEND_HDR:
> + do {
> + ret = write(fd, s->hdr + s->hdr_pos, s->hdr_len - s->hdr_pos);
> + if (ret <= 0) {
> + break;
> + }
> + s->hdr_pos += ret;
> + } while (s->hdr_pos < s->hdr_len);
> + if (ret == -1) {
> + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
> + return;
> + } else {
> + LOG("error writing header: %s", strerror(errno));
> + goto out_bad;
> + }
> + } else if (ret == 0) {
> + LOG("connected closed unexpectedly");
> + goto out_bad;
> + } else {
> + s->state = VA_SEND_BODY;
> + }
> + case VA_SEND_BODY:
> + do {
> + ret = write(fd, s->content + s->content_pos,
> + s->content_len - s->content_pos);
> + if (ret <= 0) {
> + break;
> + }
> + s->content_pos += ret;
> + } while (s->content_pos < s->content_len);
> + if (ret == -1) {
> + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
> + return;
> + } else {
> + LOG("error writing content: %s", strerror(errno));
> + goto out_bad;
> + }
> + } else if (ret == 0) {
> + LOG("connected closed unexpectedly");
> + goto out_bad;
> + } else {
> + http_status = VA_HTTP_STATUS_OK;
> + goto out;
> + }
> + default:
> + LOG("unknown state");
> + goto out_bad;
> + }
> +
> +out_bad:
> + http_status = VA_HTTP_STATUS_ERROR;
> +out:
> + s->send_cb(http_status, s->content, s->content_len);
> + qemu_set_fd_handler(fd, va_http_read_handler, NULL, NULL);
> +}
--
Thanks,
Adam