-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSocketNotifier.cpp
More file actions
69 lines (55 loc) · 1.13 KB
/
SocketNotifier.cpp
File metadata and controls
69 lines (55 loc) · 1.13 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
//
// SocketNotifier.cpp
// MessageLoop
//
// Created by Lymons on 14-3-20.
// Copyright (c) 2014年 Lymons. All rights reserved.
//
#include "SocketNotifier.h"
#include "Socket.h"
__thread int _clientID = -1;
__thread int _clientIDFromServer = -1;
SocketNotifier::SocketNotifier()
{
_socket = new Socket(this);
}
SocketNotifier::~SocketNotifier()
{
delete _socket;
}
int SocketNotifier::CreateServer()
{
return _socket->StartServer();
}
/*
* 必须在子线程中使用
*/
int SocketNotifier::CreateClient(Handler* h)
{
if (_clientID < 0) {
_clientID = _socket->StartClientConnect(_clientIDFromServer);
SetHandler(h, _clientIDFromServer);
}
return _clientID;
}
void SocketNotifier::DestoryServer(int id)
{
_socket->CloseConnect(id);
}
void SocketNotifier::DestoryClient(int id)
{
RemoveHandler(_clientIDFromServer);
_socket->CloseConnect(_clientID);
}
bool SocketNotifier::SendMessage(int id, void *m)
{
return _socket->NotifyOpposite(id);
}
void* SocketNotifier::RecvMessage(int id)
{
return NULL;
}
void SocketNotifier::StartMonitor()
{
_socket->WaitClient();
}