Mercurial > ecos
comparison packages/net/athttpd/current/src/socket.c @ 2255:3327c37c28d1
* src/socket.c: Corrected a typo that generated an assertion.
Modified slightly the source of cyg_httpd_write and cyg_httpd_writev
to make the code more consistent as to when assertions are thrown.
| author | jlarmour |
|---|---|
| date | Thu, 20 Jul 2006 18:55:04 +0000 |
| parents | 0830ae6acddc |
| children | b5670f3c40f2 |
comparison
equal
deleted
inserted
replaced
| 2254:b56324487ec7 | 2255:3327c37c28d1 |
|---|---|
| 76 cyg_uint8 cyg_httpd_thread_stack[CYG_HTTPD_DAEMON_STACK_SIZE] | 76 cyg_uint8 cyg_httpd_thread_stack[CYG_HTTPD_DAEMON_STACK_SIZE] |
| 77 __attribute__((__aligned__ (16))); | 77 __attribute__((__aligned__ (16))); |
| 78 CYG_HTTPD_STATE httpstate; | 78 CYG_HTTPD_STATE httpstate; |
| 79 | 79 |
| 80 __inline__ ssize_t | 80 __inline__ ssize_t |
| 81 cyg_httpd_write(char* buf, int len) | 81 cyg_httpd_write(char* buf, int buf_len) |
| 82 { | 82 { |
| 83 // We are not going to write anything in case | 83 // We are not going to write anything in case |
| 84 ssize_t sent = send(httpstate.sockets[httpstate.client_index].descriptor, | 84 ssize_t sent = send(httpstate.sockets[httpstate.client_index].descriptor, |
| 85 buf, | 85 buf, |
| 86 len, | 86 buf_len, |
| 87 0); | 87 0); |
| 88 CYG_ASSERT(sent == len, "send() did not send out all bytes"); | 88 CYG_ASSERT(sent == buf_len, "send() did not send out all bytes"); |
| 89 return sent; | 89 return sent; |
| 90 } | 90 } |
| 91 | 91 |
| 92 __inline__ ssize_t | 92 __inline__ ssize_t |
| 93 cyg_httpd_writev(cyg_iovec *bufs, int count) | 93 cyg_httpd_writev(cyg_iovec *iovec_bufs, int count) |
| 94 { | 94 { |
| 95 return writev(httpstate.sockets[httpstate.client_index].descriptor, | 95 int i; |
| 96 bufs, | 96 ssize_t sent = writev(httpstate.sockets[httpstate.client_index].descriptor, |
| 97 count); | 97 iovec_bufs, |
| 98 count); | |
| 99 ssize_t buf_len = 0; | |
| 100 for (i = 0; i < count; i++) | |
| 101 buf_len += iovec_bufs[i].iov_len; | |
| 102 CYG_ASSERT(sent == buf_len, "writev() did not send out all bytes"); | |
| 103 return sent; | |
| 98 } | 104 } |
| 99 | 105 |
| 100 // The need for chunked transfers arises from the fact that with dinamic | 106 // The need for chunked transfers arises from the fact that with dinamic |
| 101 // pages it is not always possible to know the packet size upfront, and thus | 107 // pages it is not always possible to know the packet size upfront, and thus |
| 102 // it is not possible to fill the Content-Length: field in the header. | 108 // it is not possible to fill the Content-Length: field in the header. |
| 139 // dynamic data we want them to be executed any every time they are | 145 // dynamic data we want them to be executed any every time they are |
| 140 // requested. | 146 // requested. |
| 141 httpstate.last_modified = -1; | 147 httpstate.last_modified = -1; |
| 142 httpstate.mime_type = cyg_httpd_find_mime_string(extension); | 148 httpstate.mime_type = cyg_httpd_find_mime_string(extension); |
| 143 cyg_int32 header_length = cyg_httpd_format_header(); | 149 cyg_int32 header_length = cyg_httpd_format_header(); |
| 144 ssize_t sent = send(httpstate.sockets[httpstate.client_index].descriptor, | 150 return cyg_httpd_write(httpstate.outbuffer, header_length); |
| 145 httpstate.outbuffer, | |
| 146 header_length, | |
| 147 0); | |
| 148 CYG_ASSERT(sent == header_length, "Did not send out all header bytes"); | |
| 149 return sent; | |
| 150 } | 151 } |
| 151 | 152 |
| 152 ssize_t | 153 ssize_t |
| 153 cyg_httpd_write_chunked(char* buf, int len) | 154 cyg_httpd_write_chunked(char* buf, int len) |
| 154 { | 155 { |
| 160 iovec_bufs[1].iov_len = len; | 161 iovec_bufs[1].iov_len = len; |
| 161 iovec_bufs[2].iov_len = 2; | 162 iovec_bufs[2].iov_len = 2; |
| 162 if (httpstate.mode & CYG_HTTPD_SEND_HEADER_ONLY) | 163 if (httpstate.mode & CYG_HTTPD_SEND_HEADER_ONLY) |
| 163 return (iovec_bufs[0].iov_len + iovec_bufs[1].iov_len + | 164 return (iovec_bufs[0].iov_len + iovec_bufs[1].iov_len + |
| 164 iovec_bufs[2].iov_len); | 165 iovec_bufs[2].iov_len); |
| 165 ssize_t sent = cyg_httpd_writev(iovec_bufs, 3); | 166 return cyg_httpd_writev(iovec_bufs, 3); |
| 166 CYG_ASSERT(sent == (iovec_bufs[0].iov_len + iovec_bufs[1].iov_len + | |
| 167 iovec_bufs[1].iov_len), | |
| 168 "Writev did not send out all bytes"); | |
| 169 return sent; | |
| 170 } | 167 } |
| 171 | 168 |
| 172 void | 169 void |
| 173 cyg_httpd_end_chunked(void) | 170 cyg_httpd_end_chunked(void) |
| 174 { | 171 { |
