MCPcopy Create free account
hub / github.com/SIPp/sipp / write

Method write

src/socket.cpp:2188–2256  ·  view source on GitHub ↗

Write data to a socket. */

Source from the content-addressed store, hash-verified

2186
2187/* Write data to a socket. */
2188int 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 (&currentTime);
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(&currentTime, 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(&currentTime, 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(&currentTime, 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"

Callers 8

PrintErrorCountsMethod · 0.80
ErrorFunction · 0.80
ProcessFileFunction · 0.80
PrintUsageFunction · 0.80
PrintCategoriesFunction · 0.80
send_rawMethod · 0.80
sendCmdMessageMethod · 0.80
sendCmdBufferMethod · 0.80

Calls 5

TRACE_MSGFunction · 0.85
get_trimmed_call_idFunction · 0.85
TRACE_SHORTMSGFunction · 0.85
get_header_contentFunction · 0.85
get_first_lineFunction · 0.85

Tested by

no test coverage detected