-------------------------------------------------------------------------*\ * Send with timeout * On windows, if you try to send 10MB, the OS will buffer EVERYTHING * this can take an awful lot of time and we will end up blocked. * Therefore, whoever calls this function should not pass a huge buffer. \*-------------------------------------------------------------------------*/
| 199 | * Therefore, whoever calls this function should not pass a huge buffer. |
| 200 | \*-------------------------------------------------------------------------*/ |
| 201 | int socket_send(p_socket ps, const char *data, size_t count, |
| 202 | size_t *sent, p_timeout tm) |
| 203 | { |
| 204 | int err; |
| 205 | *sent = 0; |
| 206 | /* avoid making system calls on closed sockets */ |
| 207 | if (*ps == SOCKET_INVALID) return IO_CLOSED; |
| 208 | /* loop until we send something or we give up on error */ |
| 209 | for ( ;; ) { |
| 210 | /* try to send something */ |
| 211 | int put = send(*ps, data, (int) count, 0); |
| 212 | /* if we sent something, we are done */ |
| 213 | if (put > 0) { |
| 214 | *sent = put; |
| 215 | return IO_DONE; |
| 216 | } |
| 217 | /* deal with failure */ |
| 218 | err = WSAGetLastError(); |
| 219 | /* we can only proceed if there was no serious error */ |
| 220 | if (err != WSAEWOULDBLOCK) return err; |
| 221 | /* avoid busy wait */ |
| 222 | if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | /*-------------------------------------------------------------------------*\ |
| 227 | * Sendto with timeout |
nothing calls this directly
no test coverage detected