| 149 | |
| 150 | |
| 151 | uint Socket::send(const byte* buf, unsigned int sz, unsigned int& written) |
| 152 | { |
| 153 | const byte* pos = buf; |
| 154 | const byte* end = pos + sz; |
| 155 | |
| 156 | wouldBlock_ = false; |
| 157 | |
| 158 | /* Remove send()/recv() hooks once non-blocking send is implemented. */ |
| 159 | while (pos != end) { |
| 160 | int sent = send_func_(ptr_, pos, static_cast<int>(end - pos)); |
| 161 | if (sent == -1) { |
| 162 | if (get_lastError() == SOCKET_EWOULDBLOCK || |
| 163 | get_lastError() == SOCKET_EAGAIN) { |
| 164 | wouldBlock_ = true; // would have blocked this time only |
| 165 | nonBlocking_ = true; // nonblocking, win32 only way to tell |
| 166 | return 0; |
| 167 | } |
| 168 | return static_cast<uint>(-1); |
| 169 | } |
| 170 | pos += sent; |
| 171 | written += sent; |
| 172 | } |
| 173 | |
| 174 | return sz; |
| 175 | } |
| 176 | |
| 177 | |
| 178 | uint Socket::receive(byte* buf, unsigned int sz) |