Commit de68aeab by NitefullWind

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

parent e6642d71
......@@ -15,11 +15,11 @@
//#define SERVERIP "172.16.13.87"
#define SERVERPORT 23770
#define MakeError(msg, ...) \
#define MakeError(msg, ...) \
strset(ErrorMsg, 0); \
sprintf(ErrorMsg, msg, __VA_ARGS__); \
_error = Freemud::Error(FM_ERROR_CODE_SOCKET, ErrorMsg); \
Log(ErrorMsg); \
LOG() << ErrorMsg; \
isOk = false;
extern "C" {
......@@ -31,7 +31,7 @@ extern "C" {
bool isOk = true;
Freemud::Error _error;
char ErrorMsg[1000] = {0};
char ErrorMsg[2048] = {0};
//Log("Initialising Winsock...");
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
......@@ -62,7 +62,7 @@ extern "C" {
MakeError("Error. Send error: %d. Server: %s, Port: %d", WSAGetLastError(), SERVERIP, SERVERPORT)
}
if (isOk) {
Log("Send data: %s", req);
LOG() << "Send data: " << req;
}
int recv_size = SOCKET_ERROR;
......@@ -81,7 +81,7 @@ extern "C" {
}
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) {
sprintf(ErrorMsg, "{\"statusCode\": 104, \"msg\": \"本地Socket通讯错误(%s).\"}", _error.Msg().c_str());
strcpy(rsp, ErrorMsg);
......
No preview for this file type
......@@ -9,16 +9,16 @@ int _Recv(SOCKET socket, char *ptr, int length)
do {
if( (totalLen = recv(socket, ptr, length, 0)) < 0) {
if (totalLen == EINTR) {
Log("Error: EINTR.");
LOG() << "Error: EINTR.";
continue;
}
Log("Error: other recv error.");
LOG() << "Error: other recv error.";
return totalLen;
} else if( totalLen == 0) {
Log("Error: connect closed.");
LOG() << "Error: connect closed.";
return 0;
}
Log("Total: Size:%d, Data:%s", totalLen, ptr);
LOG() << "Total: Size: " << totalLen <<" Data: " << ptr;
} while(0);
return totalLen;
......@@ -67,7 +67,7 @@ int Recv(SOCKET socket, char *ptr, unsigned int byteSize)
}
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[] tempBuf;
return FMError_BufferOverflow.Code();
......
......@@ -16,7 +16,7 @@ int Send(SOCKET socket, const char *ptr)
#endif
int tempLen = -1;
if( (tempLen = send(socket, sendData, sendLength, 0)) < 0) {
Log("Error: other error.");
LOG() << "Error: other error.";
}
#ifdef NeedSocketHeaderSend
......
......@@ -21,7 +21,7 @@
#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};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;
// 设置超时时间
......
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