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

Method rcvfrom

C++/unixdgram.cpp:124–145  ·  view source on GitHub ↗

* @brief Receive data and store the sender's address * * @param buf Receive buffer * @param length Length of `buf` * @param source Buffer for sender's path * @param source_len `source`'s length * @param recvfrom_flags Flags for `recvfrom(2)` * * @returns How many bytes were received. Returns -1 if the socket was created * with SOCK_NONBLOCK and errno is EWOULDBLOCK. */

Source from the content-addressed store, hash-verified

122 * with SOCK_NONBLOCK and errno is EWOULDBLOCK.
123 */
124ssize_t unix_dgram::rcvfrom(void* buf, size_t length, char* source,
125 size_t source_len, int recvfrom_flags) {
126 if (buf == NULL)
127 throw socket_exception(__FILE__, __LINE__,
128 "unix_dgram::rcvfrom: Buffer is NULL!", false);
129
130 ssize_t bytes;
131
132 bytes = recvfrom_unix_dgram_socket(sfd, buf, length, source, source_len,
133 recvfrom_flags);
134
135 if (bytes < 0) {
136 if (is_nonblocking && errno == EWOULDBLOCK)
137 return -1;
138 else
139 throw socket_exception(
140 __FILE__, __LINE__,
141 "unix_dgram::rcvfrom: Could not receive data from peer!");
142 }
143
144 return bytes;
145}
146
147/**
148 * @brief Receive data and store the sender's address

Callers 4

mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 2

socket_exceptionClass · 0.85

Tested by

no test coverage detected