-------------------------------------------------------------------------*\ * Send with timeout \*-------------------------------------------------------------------------*/
| 200 | * Send with timeout |
| 201 | \*-------------------------------------------------------------------------*/ |
| 202 | int socket_send(p_socket ps, const char *data, size_t count, |
| 203 | size_t *sent, p_timeout tm) |
| 204 | { |
| 205 | int err; |
| 206 | *sent = 0; |
| 207 | /* avoid making system calls on closed sockets */ |
| 208 | if (*ps == SOCKET_INVALID) return IO_CLOSED; |
| 209 | /* loop until we send something or we give up on error */ |
| 210 | for ( ;; ) { |
| 211 | long put = (long) send(*ps, data, count, 0); |
| 212 | /* if we sent anything, we are done */ |
| 213 | if (put >= 0) { |
| 214 | *sent = put; |
| 215 | return IO_DONE; |
| 216 | } |
| 217 | err = errno; |
| 218 | /* EPIPE means the connection was closed */ |
| 219 | if (err == EPIPE) return IO_CLOSED; |
| 220 | /* we call was interrupted, just try again */ |
| 221 | if (err == EINTR) continue; |
| 222 | /* if failed fatal reason, report error */ |
| 223 | if (err != EAGAIN) return err; |
| 224 | /* wait until we can send something or we timeout */ |
| 225 | if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err; |
| 226 | } |
| 227 | /* can't reach here */ |
| 228 | return IO_UNKNOWN; |
| 229 | } |
| 230 | |
| 231 | /*-------------------------------------------------------------------------*\ |
| 232 | * Sendto with timeout |
nothing calls this directly
no test coverage detected