|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 */ |
|
16 #ifndef __SOCKET_H__ |
|
17 #define __SOCKET_H__ |
|
18 |
|
19 #include <WinSock2.h> |
|
20 |
|
21 #include <string> |
|
22 |
|
23 |
|
24 typedef std::string String; |
|
25 |
|
26 |
|
27 class Socket { |
|
28 public: |
|
29 |
|
30 virtual ~Socket(); |
|
31 Socket(); |
|
32 Socket(const Socket&); |
|
33 Socket& operator=(Socket&); |
|
34 |
|
35 String ReceiveLine(); |
|
36 String ReceiveBytes(); |
|
37 int ReceiveBytes(BYTE *data, int bytes); |
|
38 int Peek(BYTE* data, int bytes ); |
|
39 |
|
40 void Close(); |
|
41 |
|
42 // The parameter of SendLine is not a const reference |
|
43 // because SendLine modifes the String passed. |
|
44 void SendLine (String); |
|
45 |
|
46 // The parameter of SendBytes is a const reference |
|
47 // because SendBytes does not modify the String passed |
|
48 // (in contrast to SendLine). |
|
49 void SendBytes(const String&); |
|
50 int SendBytes(const BYTE* data, int bytes); |
|
51 |
|
52 protected: |
|
53 friend class SocketServer; |
|
54 friend class SocketSelect; |
|
55 |
|
56 Socket(SOCKET s); |
|
57 |
|
58 |
|
59 |
|
60 SOCKET s_; |
|
61 |
|
62 int* refCounter_; |
|
63 |
|
64 private: |
|
65 static void Start(); |
|
66 static void End(); |
|
67 static int nofSockets_; |
|
68 }; |
|
69 |
|
70 class SocketClient : public Socket { |
|
71 public: |
|
72 SocketClient(const String& host, int port); |
|
73 }; |
|
74 |
|
75 |
|
76 class SocketServer// : public Socket |
|
77 { |
|
78 public: |
|
79 SocketServer(); |
|
80 void Accept(Socket*& s, int port, int connections, String& remoteHost); |
|
81 void Connect(Socket* s, const char* remoteHost, int remotePort); |
|
82 }; |
|
83 |
|
84 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/wsapiref_2tiq.asp |
|
85 class SocketSelect { |
|
86 public: |
|
87 SocketSelect(Socket const * const s1, Socket const * const s2); |
|
88 |
|
89 bool Readable(Socket const * const s); |
|
90 |
|
91 private: |
|
92 fd_set fds_; |
|
93 }; |
|
94 |
|
95 |
|
96 #endif |