Develop and Download Open Source Software

Browse Subversion Repository

Contents of /connection/SocketSet.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 338 - (show annotations) (download) (as text)
Mon Apr 7 13:50:32 2008 UTC (16 years ago) by satofumi
File MIME type: text/x-c++src
File size: 1411 byte(s)
VC8 の警告を少し取り除いた
1 /*!
2 \file
3 \brief 通信ソケット管理
4
5 \author Satofumi KAMIMURA
6
7 $Id$
8 */
9
10 #include "SocketSet.h"
11 #include "TcpipCtrl.h"
12
13 using namespace beego;
14
15
16 /*!
17 \brief SocketSet の内部クラス
18 */
19 struct SocketSet::pImpl {
20 size_t max_num;
21 size_t hold_num;
22 SDLNet_SocketSet socket_set;
23
24 #if !HAVE_CONFIG_H || HAVE_LIBSDL_NET
25 pImpl(size_t size)
26 : max_num(size), hold_num(0),
27 socket_set(SDLNet_AllocSocketSet(static_cast<int>(max_num))) {
28 }
29 #else
30 pImpl(size_t size) : max_num(size), hold_num(0), socket_set(NULL) {
31 }
32 #endif
33
34 ~pImpl(void) {
35 #if !HAVE_CONFIG_H || HAVE_LIBSDL_NET
36 SDLNet_FreeSocketSet(socket_set);
37 #endif
38 }
39 };
40
41
42 SocketSet::SocketSet(size_t size) : pimpl(new pImpl(size)) {
43 }
44
45
46 SocketSet::~SocketSet(void) {
47 }
48
49
50 bool SocketSet::add(TCPsocket socket) {
51 #if !HAVE_CONFIG_H || HAVE_LIBSDL_NET
52 if (pimpl->hold_num < pimpl->max_num) {
53 if (SDLNet_TCP_AddSocket(pimpl->socket_set, socket) >= 0) {
54 ++(pimpl->hold_num);
55 return true;
56 }
57 }
58 return false;
59 #else
60 return false;
61 #endif
62 }
63
64
65 void SocketSet::del(TCPsocket socket) {
66 #if !HAVE_CONFIG_H || HAVE_LIBSDL_NET
67 if ((pimpl->hold_num > 0) &&
68 (SDLNet_TCP_DelSocket(pimpl->socket_set, socket) >= 0)) {
69 --(pimpl->hold_num);
70 }
71 #endif
72 }
73
74
75 size_t SocketSet::check(int timeout) {
76 #if !HAVE_CONFIG_H || HAVE_LIBSDL_NET
77 return SDLNet_CheckSockets(pimpl->socket_set, timeout);
78 #else
79 return 0;
80 #endif
81 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26