|
|
@@ -427,27 +427,31 @@ TCPClient* TCPListener::acceptClient() { |
|
|
|
//// TCPClient methods ///////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
int TCPClient::transmit(const char* bfr, int size) { // How to send a buffer of data. |
|
|
|
LastError = 0; // No errors yet. |
|
|
|
if(0 == size) return 0; // Nothing to send, send nothing. |
|
|
|
if(0 == bfr) // Watch out for null buffers. |
|
|
|
throw Networking::SocketWriteError("TCPClient::transmit() NULL Bfr!"); |
|
|
|
if(0 > size) // Watch out for bad sizes. |
|
|
|
throw Networking::SocketWriteError("TCPClient::transmit() 0 > size!"); |
|
|
|
|
|
|
|
int ByteCount = send(Handle, bfr, size, MSG_NOSIGNAL); // Try to send and capture the count. |
|
|
|
if(0 > ByteCount) ByteCount = 0; // Mask error results as 0 bytes sent. |
|
|
|
|
|
|
|
if(size > ByteCount) { // If we didn't send it all check it out. |
|
|
|
LastError = Network.getLastError(); // Grab the error code. |
|
|
|
if(Network.WouldBlock(LastError)) { // If the error was WouldBlock then |
|
|
|
return ByteCount; // it was a partial send - return. |
|
|
|
LastError = 0; // No errors yet.
|
|
|
|
int ByteCount = 0; // No bytes sent yet this pass.
|
|
|
|
ByteCount = send(Handle, bfr, size, MSG_NOSIGNAL); // Try to send and capture the count. |
|
|
|
LastError = Network.getLastError(); // Grab any error code.
|
|
|
|
|
|
|
|
bool AnErrorOccurred = (0 > ByteCount); // How to know if an error occurred.
|
|
|
|
const int NoBytesSent = 0; // This is our "Would Block" result.
|
|
|
|
|
|
|
|
if(AnErrorOccurred) { // If there was an error check it out. |
|
|
|
if(Network.WouldBlock(LastError)) { // If the error was "Would Block" then |
|
|
|
return NoBytesSent; // return no bytes sent (try again). |
|
|
|
} else { // If this was a different kind of error |
|
|
|
throw Networking::SocketWriteError( // then throw! |
|
|
|
Network.DescriptiveError( |
|
|
|
"TCPClient::transmit().send()", LastError)); |
|
|
|
} |
|
|
|
} |
|
|
|
return ByteCount; // Ultimately return the byte count. |
|
|
|
|
|
|
|
return ByteCount; // Usually: return the sent byte count. |
|
|
|
} |
|
|
|
|
|
|
|
int TCPClient::receive(char* bfr, int size) { // How to receive a buffer of data. |