mirror of
https://github.com/besterprotocol/bformat
synced 2023-12-13 21:30:24 +01:00
BClient
- Translated `receiveMessage(ref byte[])` over to using the `Stream`, `stream` - Translated `sendMessage(byte[])` over to using the `Stream`, `stream`
This commit is contained in:
parent
b94c433115
commit
3a9fccb3f2
|
@ -43,24 +43,20 @@ public class BClient
|
|||
/* Construct a buffer to receive into */
|
||||
byte[] receiveBuffer;
|
||||
|
||||
bool status = true;
|
||||
|
||||
|
||||
/* The amount of bytes received */
|
||||
long bytesReceived;
|
||||
|
||||
/* Get the length of the message */
|
||||
byte[4] messageLengthBytes;
|
||||
bytesReceived = socket.receive(messageLengthBytes, cast(SocketFlags)MSG_WAITALL);
|
||||
|
||||
/* If there was an error reading from the socket */
|
||||
if(!(bytesReceived > 0))
|
||||
try
|
||||
{
|
||||
status = false;
|
||||
stream.readFully(messageLengthBytes);
|
||||
}
|
||||
/* If the receive was successful */
|
||||
else
|
||||
catch(StreamException streamErr)
|
||||
{
|
||||
/* If there was an error reading from the socket */
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* Response message length */
|
||||
uint messageLength;
|
||||
|
||||
|
@ -87,21 +83,19 @@ public class BClient
|
|||
|
||||
/* Read the full message */
|
||||
receiveBuffer.length = messageLength;
|
||||
bytesReceived = socket.receive(receiveBuffer, cast(SocketFlags)MSG_WAITALL);
|
||||
|
||||
/* If there was an error reading from the socket */
|
||||
if(!(bytesReceived > 0))
|
||||
{
|
||||
status = false;
|
||||
}
|
||||
/* If there was no error receiving the message */
|
||||
else
|
||||
try
|
||||
{
|
||||
stream.readFully(receiveBuffer);
|
||||
receiveMessage = receiveBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
/* If there was no error receiving the message */
|
||||
return true;
|
||||
}
|
||||
catch(StreamException streamErr)
|
||||
{
|
||||
/* If there was an error reading from the socket */
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,7 +140,7 @@ public class BClient
|
|||
messageBuffer ~= cast(byte[])message;
|
||||
|
||||
/* Send the message */
|
||||
long bytesSent = socket.send(messageBuffer);
|
||||
long bytesSent = stream.writeFully(messageBuffer);
|
||||
|
||||
/* TODO: Compact this */
|
||||
return bytesSent > 0;
|
||||
|
|
Loading…
Reference in a new issue