MCPcopy Create free account
hub / github.com/dermesser/libsocket / snd

Method snd

C++/streamclient.cpp:243–270  ·  view source on GitHub ↗

* @brief Send data to socket * * @param buf Data to be sent * @param len Length of `buf` * @param flags Flags for `send(2)`. WARNING: Throws an exception if `send()` * returns -1; this may be the case if the flag `MSG_DONTWAIT` is used. * * @returns The number of bytes sent to the peer. -1 if the socket is * non-blocking and no data was sent. * */

Source from the content-addressed store, hash-verified

241 *
242 */
243ssize_t stream_client_socket::snd(const void* buf, size_t len, int flags) {
244 ssize_t snd_bytes;
245
246 if (shut_wr == true)
247 throw socket_exception(
248 __FILE__, __LINE__,
249 "stream_client_socket::snd() - Socket has already been shut down!",
250 false);
251 if (sfd == -1)
252 throw socket_exception(
253 __FILE__, __LINE__,
254 "stream_client_socket::snd() - Socket not connected!", false);
255 if (buf == NULL || len == 0)
256 throw socket_exception(
257 __FILE__, __LINE__,
258 "stream_client_socket::snd() - Buffer or length is null!", false);
259
260 if (-1 == (snd_bytes = BERKELEY::send(sfd, buf, len, flags))) {
261 if (is_nonblocking && errno == EWOULDBLOCK)
262 return -1;
263 else
264 throw socket_exception(
265 __FILE__, __LINE__,
266 "stream_client_socket::snd() - Error while sending");
267 }
268
269 return snd_bytes;
270}
271
272/**
273 * @brief Shut a socket down

Callers

nothing calls this directly

Calls 1

socket_exceptionClass · 0.85

Tested by

no test coverage detected