MCPcopy Create free account
hub / github.com/brainflow-dev/brainflow / recv

Method recv

src/utils/socket_server_tcp.cpp:119–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117}
118
119int SocketServerTCP::recv (void *data, int size)
120{
121 if (connected_socket == INVALID_SOCKET)
122 {
123 return -1;
124 }
125 int res = ::recv (connected_socket, (char *)data, size, 0);
126 if (res == SOCKET_ERROR)
127 {
128 return -1;
129 }
130 for (int i = 0; i < res; i++)
131 {
132 temp_buffer.push (((char *)data)[i]);
133 }
134 // before we used SO_RCVLOWAT but it didnt work well
135 // and we were not sure that it works correctly with timeout
136 if (recv_all_or_nothing)
137 {
138 if ((int)temp_buffer.size () < size)
139 {
140 return 0;
141 }
142 for (int i = 0; i < size; i++)
143 {
144 ((char *)data)[i] = temp_buffer.front ();
145 temp_buffer.pop ();
146 }
147 return size;
148 }
149 else
150 {
151 for (int i = 0; i < res; i++)
152 {
153 ((char *)data)[i] = temp_buffer.front ();
154 temp_buffer.pop ();
155 }
156 return res;
157 }
158}
159
160void SocketServerTCP::close ()
161{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected