Documentation of SFML 1.6

Warning: this page refers to an old version of SFML. Click here to switch to the latest version.
SocketTCP.hpp
1 
2 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 #ifndef SFML_SOCKETTCP_HPP
26 #define SFML_SOCKETTCP_HPP
27 
29 // Headers
31 #include <SFML/Network/SocketHelper.hpp>
32 #include <vector>
33 
34 
35 namespace sf
36 {
37 class Packet;
38 class IPAddress;
39 template <typename> class Selector;
40 
45 class SFML_API SocketTCP
46 {
47 public :
48 
53  SocketTCP();
54 
62  void SetBlocking(bool Blocking);
63 
74  Socket::Status Connect(unsigned short Port, const IPAddress& HostAddress, float Timeout = 0.f);
75 
84  bool Listen(unsigned short Port);
85 
96  Socket::Status Accept(SocketTCP& Connected, IPAddress* Address = NULL);
97 
107  Socket::Status Send(const char* Data, std::size_t Size);
108 
120  Socket::Status Receive(char* Data, std::size_t MaxSize, std::size_t& SizeReceived);
121 
130  Socket::Status Send(Packet& PacketToSend);
131 
141  Socket::Status Receive(Packet& PacketToReceive);
142 
149  bool Close();
150 
158  bool IsValid() const;
159 
168  bool operator ==(const SocketTCP& Other) const;
169 
178  bool operator !=(const SocketTCP& Other) const;
179 
190  bool operator <(const SocketTCP& Other) const;
191 
192 private :
193 
194  friend class Selector<SocketTCP>;
195 
203  SocketTCP(SocketHelper::SocketType Descriptor);
204 
211  void Create(SocketHelper::SocketType Descriptor = 0);
212 
214  // Member data
216  SocketHelper::SocketType mySocket;
217  Uint32 myPendingHeader;
218  Uint32 myPendingHeaderSize;
219  std::vector<char> myPendingPacket;
220  Int32 myPendingPacketSize;
221  bool myIsBlocking;
222 };
223 
224 } // namespace sf
225 
226 
227 #endif // SFML_SOCKETTCP_HPP