Skip to content

Commit a565e30

Browse files
committed
update code,server is stable now
1 parent 546a2af commit a565e30

File tree

10 files changed

+25
-26
lines changed

10 files changed

+25
-26
lines changed

AccSvr/AccountSvr.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ void AccountSvr::DestructNetWorkObj(NetWorkObject *netobj)
3939
return;
4040
}
4141

42-
close(session->getSocket()); //close socket
43-
44-
4542
SESSION_TYPE type = session->getType();
4643
if ( eClient == type)
4744
{

DBSvr/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ int main()
2828

2929

3030
//multi thread ignore SIGPIPE
31+
/*
3132
sigset_t bset, oset;
3233
sigemptyset(&bset);
3334
sigaddset(&bset, SIGPIPE);
3435
if (pthread_sigmask(SIG_BLOCK, &bset, &oset) != 0)
3536
{
3637
printf("set thread signal mask fail!\n");
3738
}
39+
*/
3840

3941
DBSvr* dbsvr = DBSvr::GetInstance();
4042
LOGI("Hello world! ServerID is:" << dbsvr->getServerID());

include/CIoThread.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CIoThread: public CBaseThread
3838
//isRecvEvent = false;
3939
CSession *session = (CSession *)epEvent[i].data.ptr;
4040
int32 oplen = 0;
41-
if (epEvent[i].events & EPOLLIN && session->getStatus() != waitdel) // recv msg
41+
if (epEvent[i].events & EPOLLIN) // recv msg
4242
{
4343
oplen = session->onRecv();
4444

@@ -56,7 +56,7 @@ class CIoThread: public CBaseThread
5656

5757
#if 1 //double check sendbuf
5858

59-
if (epEvent[i].events & EPOLLOUT && session->getStatus() != waitdel) // send msg
59+
if (epEvent[i].events & EPOLLOUT) // send msg
6060
{
6161
oplen = session->sendToSocket();
6262
if (0 == oplen)

include/EpollServer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class EpollServer
142142
std::multimap<SESSION_TYPE, CSession *>::iterator it;
143143
for (it = m_ServerSessionMap.begin(); it != m_ServerSessionMap.end(); )
144144
{
145-
if (it->second->getSessionId() == session->getSessionId())
145+
if (it->second == session)
146146
{
147147
m_ServerSessionMap.erase(it++);
148148
//put in connector errrolist, wait for reconnect... !!!!todo.....verify not connector session
@@ -173,7 +173,7 @@ class EpollServer
173173
{
174174
for (it = m_ServerSessionMap.begin(); it != m_ServerSessionMap.end(); it++)
175175
{
176-
if (it->first == type && (it->second)->getStatus() == active)
176+
if (it->first == type)
177177
{
178178
return it->second;
179179
}

include/baseHeader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ enum eSESSIONSTATUS
8080
waitdel = 3, // deactive, need to remove
8181
registered = 4,//registered
8282
sock_SIGPIPE = 5, //recv signal pipe
83+
sock_unused = 6, //still in poll not working
8384
};
8485

8586

make

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/sh
22

33
if [ $# -lt 1 ]; then
4-
echo "back args!!!"
4+
echo "bad args!!!"
5+
echo "usage: ./make [all|serverName]"
56
exit 1
67
fi
78

network/include/Session.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ class CSession
8989
return m_ptrServer;
9090
}
9191

92+
inline void closeSocket()
93+
{
94+
if (m_socket != -1)
95+
{
96+
close(m_socket);
97+
}
98+
}
9299
int32 processSend(uint16 sysid, uint16 msgid, char *msg, int32 msgsize)
93100
{
94101
#if 0

network/src/Connector.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "../include/Connector.h"
22
#include "../../common/SIDGenerator.hpp"
33

4-
//static sem_t m_waitSem;
5-
64
Connector::Connector()
75
{
86
m_sessionFactory.init(2,2);
@@ -44,31 +42,24 @@ void Connector::addToErrorList(CSession *session)
4442
void Connector::reConnectAll()
4543
{
4644
m_connErrListLock.lock();
47-
std::vector<CSession *> sessionvec;
4845

4946
if (!m_connErrList.empty())
5047
{
51-
sessionvec.reserve(m_connErrList.size());
5248
CommonList<CSession>::iterator iter;
5349
for (iter = m_connErrList.begin(); iter != m_connErrList.end(); )
5450
{
5551
if (preReConnect(*iter))
5652
{
57-
sessionvec.push_back(*iter);
53+
addToWaitList(*iter);
5854
m_connErrList.erase(iter++);
5955
}
6056
}
6157
}
6258
m_connErrListLock.unLock();
63-
for (uint32 i = 0; i < sessionvec.size(); i++)
64-
{
65-
addToWaitList(sessionvec[i]);
66-
}
6759
}
6860

6961
bool Connector::preReConnect(CSession *session)
7062
{
71-
close(session->getSocket());//close the old socket
7263
Int32 cliSock = socket(AF_INET, SOCK_STREAM, 0); //create a new socket
7364
if (cliSock < 0)
7465
{
@@ -175,3 +166,4 @@ void* Connector::threadRoutine(void *args)
175166
}
176167
return NULL;
177168
}
169+

network/src/Session.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
#include "../../Factory/BaseFactory.h"
33
#include "../../include/EpollServer.hpp"
44

5-
CSession::CSession() : m_pBindNetWorkObj(NULL), m_connSvrID(0), m_bIsFromSelf(false)
5+
CSession::CSession() : m_socket(-1),m_pBindNetWorkObj(NULL), m_connSvrID(0), m_bIsFromSelf(false)
66
{
7-
m_socket = -1;
87
m_boActive = false;
98
#if 0
109
m_recvBuff.init(SESSIONBUFLEN, SESSIONBUFLEN);
1110
m_sendBuff.init(SESSIONBUFLEN, SESSIONBUFLEN);
1211
#endif
1312

14-
m_pBindNetWorkObj = NULL;
1513
m_nSessionId = 0;
1614
m_LeftPkgBuf = new char[MAXPKGLEN];
1715
assert(m_LeftPkgBuf != NULL);
@@ -32,7 +30,7 @@ CSession::~CSession()
3230
m_pBindNetWorkObj = NULL;
3331
}
3432

35-
close(m_socket);
33+
closeSocket();
3634
}
3735

3836
void CSession::clear() // call when reuse
@@ -50,8 +48,9 @@ void CSession::clear() // call when reuse
5048
getServer()->DestructNetWorkObj(m_pBindNetWorkObj);
5149
m_RecvBufManager.clear();
5250
m_SendBufManager.clear();
53-
close(m_socket);
51+
closeSocket();
5452
m_pBindNetWorkObj = NULL;
53+
m_eStatus = sock_unused;
5554
}
5655

5756
#if 0
@@ -100,7 +99,7 @@ int32 CSession::onRecv()
10099
recvlen = recv(m_socket, (void *)(curpkg->getPkgWritePos()), leftLen, 0);
101100
if (0 == recvlen)
102101
{
103-
printf("====================socket!!!!!!!!recv return 0!!!!!!!!errno:%d\n", errno);
102+
printf("====================socket!!!!!!!!recv return 0!!!!!!!!errno:%d EAGAIN:%d\n", errno, EAGAIN);
104103
perror("recv error");
105104
return -1;
106105
} else if (ispkgbody && (leftLen == recvlen)) // why we return? !!! avoid the infinity loop while the socket buf is always get data from a very busy send client

testclient/TestClient.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,14 @@ void TestClient::update()
320320
{
321321
while (true)
322322
{
323-
if (acct_time::getCurTimeMs() >= m_nNextTick)
323+
if (true || acct_time::getCurTimeMs() >= m_nNextTick)
324324
{
325325
m_nNextTick = acct_time::getCurTimeMs() + 100;
326326
updateSessionList(); // handle new Session
327327
handleActiveSession();
328328
removeDeadSession();
329329
}
330-
//acct_time::sleepMs(1); // sleep 1ms per loop
330+
acct_time::sleepMs(100); // sleep 1ms per loop
331331
}
332332

333333
}

0 commit comments

Comments
 (0)