Commit de68aeab by NitefullWind

1. 修复日志太长时崩溃Bug。

parent e6642d71
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
strset(ErrorMsg, 0); \ strset(ErrorMsg, 0); \
sprintf(ErrorMsg, msg, __VA_ARGS__); \ sprintf(ErrorMsg, msg, __VA_ARGS__); \
_error = Freemud::Error(FM_ERROR_CODE_SOCKET, ErrorMsg); \ _error = Freemud::Error(FM_ERROR_CODE_SOCKET, ErrorMsg); \
Log(ErrorMsg); \ LOG() << ErrorMsg; \
isOk = false; isOk = false;
extern "C" { extern "C" {
...@@ -31,7 +31,7 @@ extern "C" { ...@@ -31,7 +31,7 @@ extern "C" {
bool isOk = true; bool isOk = true;
Freemud::Error _error; Freemud::Error _error;
char ErrorMsg[1000] = {0}; char ErrorMsg[2048] = {0};
//Log("Initialising Winsock..."); //Log("Initialising Winsock...");
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
...@@ -62,7 +62,7 @@ extern "C" { ...@@ -62,7 +62,7 @@ extern "C" {
MakeError("Error. Send error: %d. Server: %s, Port: %d", WSAGetLastError(), SERVERIP, SERVERPORT) MakeError("Error. Send error: %d. Server: %s, Port: %d", WSAGetLastError(), SERVERIP, SERVERPORT)
} }
if (isOk) { if (isOk) {
Log("Send data: %s", req); LOG() << "Send data: " << req;
} }
int recv_size = SOCKET_ERROR; int recv_size = SOCKET_ERROR;
...@@ -81,7 +81,7 @@ extern "C" { ...@@ -81,7 +81,7 @@ extern "C" {
} }
if (isOk) { if (isOk) {
Log("Recv size: %d, Recv data: %s", recv_size, rsp); LOG() << "Recv size: " << recv_size << " Recv data: " << rsp;
} else if (_error.Code() == FM_ERROR_CODE_SOCKET) { } else if (_error.Code() == FM_ERROR_CODE_SOCKET) {
sprintf(ErrorMsg, "{\"statusCode\": 104, \"msg\": \"本地Socket通讯错误(%s).\"}", _error.Msg().c_str()); sprintf(ErrorMsg, "{\"statusCode\": 104, \"msg\": \"本地Socket通讯错误(%s).\"}", _error.Msg().c_str());
strcpy(rsp, ErrorMsg); strcpy(rsp, ErrorMsg);
......
No preview for this file type
...@@ -9,16 +9,16 @@ int _Recv(SOCKET socket, char *ptr, int length) ...@@ -9,16 +9,16 @@ int _Recv(SOCKET socket, char *ptr, int length)
do { do {
if( (totalLen = recv(socket, ptr, length, 0)) < 0) { if( (totalLen = recv(socket, ptr, length, 0)) < 0) {
if (totalLen == EINTR) { if (totalLen == EINTR) {
Log("Error: EINTR."); LOG() << "Error: EINTR.";
continue; continue;
} }
Log("Error: other recv error."); LOG() << "Error: other recv error.";
return totalLen; return totalLen;
} else if( totalLen == 0) { } else if( totalLen == 0) {
Log("Error: connect closed."); LOG() << "Error: connect closed.";
return 0; return 0;
} }
Log("Total: Size:%d, Data:%s", totalLen, ptr); LOG() << "Total: Size: " << totalLen <<" Data: " << ptr;
} while(0); } while(0);
return totalLen; return totalLen;
...@@ -67,7 +67,7 @@ int Recv(SOCKET socket, char *ptr, unsigned int byteSize) ...@@ -67,7 +67,7 @@ int Recv(SOCKET socket, char *ptr, unsigned int byteSize)
} }
if (byteSize < dataLen) { // 判断接收Buffer长度是否足够 if (byteSize < dataLen) { // 判断接收Buffer长度是否足够
Log("Error. Buffer overflow, Except size: %d, Actual size: %d", byteSize, dataLen); LOG() << "Error. Buffer overflow, Except size: " << byteSize << " Actual size: " << dataLen;
delete[] recvBuf; delete[] recvBuf;
delete[] tempBuf; delete[] tempBuf;
return FMError_BufferOverflow.Code(); return FMError_BufferOverflow.Code();
......
...@@ -16,7 +16,7 @@ int Send(SOCKET socket, const char *ptr) ...@@ -16,7 +16,7 @@ int Send(SOCKET socket, const char *ptr)
#endif #endif
int tempLen = -1; int tempLen = -1;
if( (tempLen = send(socket, sendData, sendLength, 0)) < 0) { if( (tempLen = send(socket, sendData, sendLength, 0)) < 0) {
Log("Error: other error."); LOG() << "Error: other error.";
} }
#ifdef NeedSocketHeaderSend #ifdef NeedSocketHeaderSend
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "fm_log.h" #include "fm_log.h"
//#define Log(_Format, ...) {char msg[1024] = {0}; printf("Function:%s, Line:%d: ", __FUNCTION__, __LINE__); printf(_Format, __VA_ARGS__); printf("\n");} //#define Log(_Format, ...) {char msg[1024] = {0}; printf("Function:%s, Line:%d: ", __FUNCTION__, __LINE__); printf(_Format, __VA_ARGS__); printf("\n");}
#define Log(_Format, ...) {char msg[1024] = {0};sprintf(msg, _Format, __VA_ARGS__);LOG() << msg;} //#define Log(_Format, ...) {char msg[20480] = {0};sprintf(msg, _Format, __VA_ARGS__);LOG() << msg;}
const int MAX_SIZE = 4096; const int MAX_SIZE = 4096;
// 设置超时时间 // 设置超时时间
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment