diff options
Diffstat (limited to 'protocols/WhatsApp/src/WASocketConnection.cpp')
-rw-r--r-- | protocols/WhatsApp/src/WASocketConnection.cpp | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/protocols/WhatsApp/src/WASocketConnection.cpp b/protocols/WhatsApp/src/WASocketConnection.cpp index b5d1b0235c..41d0b78663 100644 --- a/protocols/WhatsApp/src/WASocketConnection.cpp +++ b/protocols/WhatsApp/src/WASocketConnection.cpp @@ -101,36 +101,38 @@ void WASocketConnection::write(const std::vector<unsigned char>& bytes, int leng unsigned char WASocketConnection::read()
{
- char c;
-
SetLastError(0);
- int result;
- //do {
- result = Netlib_Recv(this->hConn, &c, 1, 0 /*MSG_NOHTTPGATEWAYWRAP | MSG_NODUMP*/);
- //} while (WSAGetLastError() == EINTR);
- if (result <= 0) {
+
+ char c;
+ int result = Netlib_Recv(this->hConn, &c, 1, 0);
+ if (result <= 0)
throw WAException(getLastErrorMsg(), WAException::SOCKET_EX, WAException::SOCKET_EX_RECV);
- }
+
return c;
}
+int WASocketConnection::read(unsigned char *buf, int length)
+{
+ int result = Netlib_Recv(this->hConn, (char*)buf, length, 0);
+ if (result <= 0)
+ throw WAException(getLastErrorMsg(), WAException::SOCKET_EX, WAException::SOCKET_EX_RECV);
+
+ return result;
+}
+
int WASocketConnection::read(std::vector<unsigned char>& b, int off, int length)
{
- if (off < 0 || length < 0) {
+ if (off < 0 || length < 0)
throw new WAException("Out of bounds", WAException::SOCKET_EX, WAException::SOCKET_EX_RECV);
- }
- char* buffer = new char[length];
- int result = Netlib_Recv(this->hConn, buffer, length, MSG_NOHTTPGATEWAYWRAP | MSG_NODUMP);
- if (result <= 0) {
+ char* buffer = (char*)_alloca(length);
+ int result = Netlib_Recv(this->hConn, buffer, length, MSG_NOHTTPGATEWAYWRAP | MSG_NODUMP);
+ if (result <= 0)
throw WAException(getLastErrorMsg(), WAException::SOCKET_EX, WAException::SOCKET_EX_RECV);
- }
for (int i = 0; i < result; i++)
b[off + i] = buffer[i];
- delete[] buffer;
-
return result;
}
@@ -139,6 +141,21 @@ void WASocketConnection::forceShutdown() Netlib_Shutdown(this->hConn);
}
+void WASocketConnection::dump(const void *pData, int length)
+{
+ BYTE *pBuf = (BYTE*)pData;
+ while (length > 0) {
+ int portion = (length < 16) ? length : 16;
+
+ char str[100];
+ for (int i = 0; i < portion; i++)
+ sprintf(str + i * 3, "%02X ", *pBuf++);
+ Netlib_Logf(WASocketConnection::hNetlibUser, "DATA: %s", str);
+
+ length -= portion;
+ }
+}
+
WASocketConnection::~WASocketConnection()
{
this->forceShutdown();
|