|
|
|
@ -31,97 +31,83 @@ httpResponseWriterWrite(HttpResponseWriter this, int fd) |
|
|
|
&(respq->msgs[1]), |
|
|
|
sizeof(void*) * (--respq->nmsgs + 1)); |
|
|
|
|
|
|
|
this->nbuffer = httpMessageHeaderSizeGet(message); |
|
|
|
this->buffer = malloc(this->nbuffer); |
|
|
|
this->written = 0; |
|
|
|
|
|
|
|
httpMessageHeaderToString(message, this->buffer); |
|
|
|
|
|
|
|
this->state = HTTP_RESPONSE_HEADER; |
|
|
|
} |
|
|
|
else { |
|
|
|
cont = 0; |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
case HTTP_RESPONSE_HEADER: |
|
|
|
this->written += write( |
|
|
|
fd, |
|
|
|
&(this->buffer[this->written]), |
|
|
|
this->nbuffer - this->written); |
|
|
|
|
|
|
|
if (this->written == this->nbuffer) { |
|
|
|
free(this->buffer); |
|
|
|
this->buffer = NULL; |
|
|
|
this->nbuffer = 0; |
|
|
|
this->written = 0; |
|
|
|
this->pstart = 0; |
|
|
|
this->pend = 0; |
|
|
|
this->pend = httpMessageHeaderSizeGet(message); |
|
|
|
this->nheader = this->pend; |
|
|
|
httpMessageHeaderToString(message, this->pipe); |
|
|
|
|
|
|
|
this->state = HTTP_RESPONSE_PIPE; |
|
|
|
this->state = HTTP_RESPONSE_WRITE; |
|
|
|
} |
|
|
|
else { |
|
|
|
cont = 0; |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
case HTTP_RESPONSE_PIPE: |
|
|
|
switch (message->type) { |
|
|
|
case HTTP_MESSAGE_BUFFERED: |
|
|
|
this->written += write( |
|
|
|
fd, |
|
|
|
&(message->body[this->written]), |
|
|
|
message->nbody - this->written); |
|
|
|
break; |
|
|
|
|
|
|
|
case HTTP_MESSAGE_PIPED: |
|
|
|
/** |
|
|
|
* read |
|
|
|
*/ |
|
|
|
if (this->nbuffer < message->nbody) { |
|
|
|
size_t rsize; |
|
|
|
size_t temp; |
|
|
|
|
|
|
|
this->pend = (1024 == this->pend)? |
|
|
|
0 : this->pend; |
|
|
|
|
|
|
|
rsize = (this->pstart <= this->pend)? |
|
|
|
1024 - this->pend : this->pstart - 1; |
|
|
|
case HTTP_RESPONSE_WRITE: |
|
|
|
/** |
|
|
|
* read |
|
|
|
*/ |
|
|
|
if (this->nbuffer < message->nbody) { |
|
|
|
size_t temp = 0; |
|
|
|
size_t rsize; |
|
|
|
|
|
|
|
this->pend = (RESPONSE_WRITER_BUF_SIZE == this->pend)? |
|
|
|
0 : this->pend; |
|
|
|
|
|
|
|
rsize = (this->pstart <= this->pend)? |
|
|
|
RESPONSE_WRITER_BUF_SIZE - this->pend : |
|
|
|
this->pstart - 1; |
|
|
|
|
|
|
|
switch (message->type) { |
|
|
|
case HTTP_MESSAGE_BUFFERED: |
|
|
|
temp = message->nbody - this->nbuffer; |
|
|
|
temp = (rsize<temp)? rsize : temp; |
|
|
|
memcpy( |
|
|
|
&(this->pipe[this->pend]), |
|
|
|
&(message->body[this->nbuffer]), |
|
|
|
temp); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case HTTP_MESSAGE_PIPED: |
|
|
|
temp = read( |
|
|
|
message->handle, |
|
|
|
&(this->pipe[this->pend]), |
|
|
|
rsize); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
this->nbuffer += temp; |
|
|
|
this->pend += temp; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* write |
|
|
|
*/ |
|
|
|
{ |
|
|
|
size_t wsize; |
|
|
|
size_t temp; |
|
|
|
this->nbuffer += temp; |
|
|
|
this->pend += temp; |
|
|
|
} |
|
|
|
|
|
|
|
wsize = (this->pstart <= this->pend)? |
|
|
|
this->pend - this->pstart : 1024 - this->pstart; |
|
|
|
/** |
|
|
|
* write |
|
|
|
*/ |
|
|
|
{ |
|
|
|
size_t wsize; |
|
|
|
size_t temp; |
|
|
|
|
|
|
|
temp = write(fd, &(this->pipe[this->pstart]), wsize); |
|
|
|
wsize = (this->pstart <= this->pend)? |
|
|
|
this->pend - this->pstart : |
|
|
|
RESPONSE_WRITER_BUF_SIZE - this->pstart; |
|
|
|
|
|
|
|
this->written += temp; |
|
|
|
this->pstart += temp; |
|
|
|
temp = write(fd, &(this->pipe[this->pstart]), wsize); |
|
|
|
|
|
|
|
this->pstart = (1024 == this->pstart)? |
|
|
|
0 : this->pstart; |
|
|
|
} |
|
|
|
break; |
|
|
|
this->written += temp; |
|
|
|
this->pstart += temp; |
|
|
|
|
|
|
|
default: |
|
|
|
break; |
|
|
|
this->pstart = (RESPONSE_WRITER_BUF_SIZE == this->pstart)? |
|
|
|
0 : this->pstart; |
|
|
|
} |
|
|
|
|
|
|
|
if (this->written == message->nbody) { |
|
|
|
if (this->written == message->nbody + this->nheader) { |
|
|
|
if (HTTP_MESSAGE_PIPED == message->type) { |
|
|
|
close(message->handle); |
|
|
|
} |
|
|
|
this->nheader = 0; |
|
|
|
this->nbuffer = 0; |
|
|
|
this->written = 0; |
|
|
|
this->pstart = 0; |
|
|
|
|