-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSocketUser.cpp
More file actions
56 lines (49 loc) · 1020 Bytes
/
Copy pathSocketUser.cpp
File metadata and controls
56 lines (49 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/////////////////////////////////////////////////////////
//SocketUser
//
#include "stdafx.h"
#include "SocketUser.h"
#include "Chennel.h"
SocketUser::SocketUser(CChennel * cs,HubCmd * cm):HubUser(cm)
{
mSocket = cs;
if( mSocket ) sprintf(mName,"%s-%d",mSocket->mAddr,mSocket->mPort);
}
SocketUser::~SocketUser()
{
}
void SocketUser::Close()
{
unLock();
if( mSocket ) {
mSocket->CloseChennel();
delete mSocket;
HubUser::Close();
}
mSocket = NULL;
}
char * SocketUser::ReadData()
{
if( mSocket==NULL ) return 0;
int len = mSocket->CanRead();
if( len<0 ){
Trace::traceEvent(TRACE_DEBUG,"client %s read error",mName);
Close();
return NULL;
}
if( len>0 ){
char * p = GetWPtr(len);
mSocket->ReadData(p,len);
return p;
}
return NULL;
}
void SocketUser::Show(CSerial * src,const char *msg)
{
if( mSocket ) mSocket->WriteData(msg,(int)strlen(msg));
}
static char clscode[] = {0x1B, 0x5B, 0x48, 0x1B, 0x5B, 0x4A};
void SocketUser::Cls()
{
mSocket->WriteData(clscode,sizeof(clscode));
}