summaryrefslogtreecommitdiff
path: root/MySpace/server_con.cpp
diff options
context:
space:
mode:
authorsje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-07-01 17:33:01 +0000
committersje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-07-01 17:33:01 +0000
commit287cb92158ee9eeba5eac6edea7d830777810beb (patch)
tree5e7f04cf1f1c80469f6ac496ccb8fc1776beab81 /MySpace/server_con.cpp
parent7d2d0d17e720b43162433410b88ff1de7f019f38 (diff)
finally fixed packet reading code
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@236 4f64403b-2f21-0410-a795-97e2b3489a10
Diffstat (limited to 'MySpace/server_con.cpp')
-rw-r--r--MySpace/server_con.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/MySpace/server_con.cpp b/MySpace/server_con.cpp
index e7eea8d..87cb69e 100644
--- a/MySpace/server_con.cpp
+++ b/MySpace/server_con.cpp
@@ -251,14 +251,18 @@ void __cdecl ServerThreadFunc(void*) {
myspace_server_running = true;
- char *recv_buffer = new char[SERVER_READ_BUFFER_SIZE];
+ char *recv_buffer = new char[SERVER_READ_BUFFER_SIZE + 1];
int bytes = 0;
char mt[256];
int tries = 0;
bool login = true;
+ int bytes_read;
HANDLE connection = 0;
+ char *pbuff = recv_buffer, *end;
+ int buffer_bytes = 0;
+ recv_buffer[SERVER_READ_BUFFER_SIZE] = 0;
while(!Miranda_Terminated() && !server_stop) {
if(login) {
if(connection) Netlib_CloseHandle(connection);
@@ -273,7 +277,9 @@ void __cdecl ServerThreadFunc(void*) {
}
}
}
- bytes = Netlib_Recv(connection, (char *)recv_buffer, SERVER_READ_BUFFER_SIZE, MSG_DUMPASTEXT);
+ bytes = Netlib_Recv(connection, (char *)pbuff, SERVER_READ_BUFFER_SIZE - (pbuff - recv_buffer), MSG_DUMPASTEXT);
+ buffer_bytes += bytes;
+ pbuff[bytes] = 0;
if(bytes == 0) {
//PUShowMessage("Connection closed", SM_NOTIFY);
@@ -299,8 +305,7 @@ void __cdecl ServerThreadFunc(void*) {
DBWriteContactSettingDword(0, MODULE, "LastPort", conn_data.wPort);
}
- char *pbuff = recv_buffer, *end;
- while((end = strstr(pbuff, "\\final\\")) != 0 && (end - recv_buffer <= bytes)) {
+ while((end = strstr(pbuff, "\\final\\")) != 0) {
//mir_snprintf(mt, 256, "recvd %d bytes", bytes);
//PUShowMessage(mt, SM_NOTIFY);
end += 7;
@@ -540,7 +545,9 @@ void __cdecl ServerThreadFunc(void*) {
}
}
}
- pbuff = end;
+ buffer_bytes -= (end - pbuff);
+ memmove(recv_buffer, end, buffer_bytes);
+ pbuff = recv_buffer;
}
}
}