! \brief sends on fd (which must be O_NONBLOCK); if it cannot send any data * in timeout milliseconds it will return ERROR * \return -1 on error, or number of bytes written * (if less than len => couldn't send all) * bugs: signals will reset the timer */
| 90 | * bugs: signals will reset the timer |
| 91 | */ |
| 92 | int tsend_stream(int fd, char* buf, unsigned int len, int timeout) |
| 93 | { |
| 94 | int written; |
| 95 | TSEND_INIT; |
| 96 | |
| 97 | written=0; |
| 98 | again: |
| 99 | n=send(fd, buf, len, |
| 100 | #ifdef HAVE_MSG_NOSIGNAL |
| 101 | MSG_NOSIGNAL |
| 102 | #else |
| 103 | 0 |
| 104 | #endif |
| 105 | ); |
| 106 | TSEND_ERR_CHECK("tsend_stream"); |
| 107 | written+=n; |
| 108 | if ((unsigned int)n<len){ |
| 109 | /* partial write */ |
| 110 | buf+=n; |
| 111 | len-=n; |
| 112 | }else{ |
| 113 | /* successful full write */ |
| 114 | return written; |
| 115 | } |
| 116 | TSEND_POLL("tsend_stream"); |
| 117 | error: |
| 118 | return -1; |
| 119 | } |
| 120 | |
| 121 | |
| 122 |
no outgoing calls
no test coverage detected