Write data to a socket. */
| 2186 | |
| 2187 | /* Write data to a socket. */ |
| 2188 | int SIPpSocket::write(const char *buffer, ssize_t len, int flags, struct sockaddr_storage *dest) |
| 2189 | { |
| 2190 | int rc; |
| 2191 | |
| 2192 | if (ss_out) { |
| 2193 | rc = flush(); |
| 2194 | TRACE_MSG("Attempted socket flush returned %d\r\n", rc); |
| 2195 | if (rc < 0) { |
| 2196 | if ((errno == EWOULDBLOCK) && (flags & WS_BUFFER)) { |
| 2197 | buffer_write(buffer, len, dest); |
| 2198 | return len; |
| 2199 | } else { |
| 2200 | return rc; |
| 2201 | } |
| 2202 | } |
| 2203 | } |
| 2204 | |
| 2205 | rc = write_primitive(buffer, len, dest); |
| 2206 | struct timeval currentTime; |
| 2207 | GET_TIME (¤tTime); |
| 2208 | |
| 2209 | if (rc == len) { |
| 2210 | /* Everything is great. */ |
| 2211 | if (useMessagef == 1) { |
| 2212 | TRACE_MSG("----------------------------------------------- %s\n" |
| 2213 | "%s %smessage sent [%zu] bytes:\n\n%.*s\n", |
| 2214 | CStat::formatTime(¤tTime, true), |
| 2215 | TRANSPORT_TO_STRING(ss_transport), |
| 2216 | ss_control ? "control " : "", |
| 2217 | len, (int)len, buffer); |
| 2218 | } |
| 2219 | |
| 2220 | if (useShortMessagef == 1) { |
| 2221 | char *msg = strdup(buffer); |
| 2222 | const char *call_id = get_trimmed_call_id(msg); |
| 2223 | TRACE_SHORTMSG("%s\tS\t%s\tCSeq:%s\t%s\n", |
| 2224 | CStat::formatTime(¤tTime, rfc3339), call_id, get_header_content(msg, "CSeq:"), get_first_line(msg)); |
| 2225 | free(msg); |
| 2226 | } |
| 2227 | |
| 2228 | } else if (rc <= 0) { |
| 2229 | if ((errno == EWOULDBLOCK) && (flags & WS_BUFFER)) { |
| 2230 | buffer_write(buffer, len, dest); |
| 2231 | enter_congestion(errno); |
| 2232 | return len; |
| 2233 | } |
| 2234 | if (useMessagef == 1) { |
| 2235 | TRACE_MSG("----------------------------------------------- %s\n" |
| 2236 | "Error sending %s message:\n\n%.*s\n", |
| 2237 | CStat::formatTime(¤tTime, true), |
| 2238 | TRANSPORT_TO_STRING(ss_transport), |
| 2239 | (int)len, buffer); |
| 2240 | } |
| 2241 | return write_error(errno); |
| 2242 | } else { |
| 2243 | /* We have a truncated message, which must be handled internally to the write function. */ |
| 2244 | if (useMessagef == 1) { |
| 2245 | TRACE_MSG("----------------------------------------------- %s\n" |
no test coverage detected