/extlibs/SFML/src/SFML/Network/Unix/SocketImpl.hpp
C++ Header | 109 lines | 27 code | 14 blank | 68 comment | 0 complexity | ff550ea385e7110e5c2750eaba29c879 MD5 | raw file
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// 23//////////////////////////////////////////////////////////// 24 25#ifndef SFML_SOCKETIMPL_HPP 26#define SFML_SOCKETIMPL_HPP 27 28//////////////////////////////////////////////////////////// 29// Headers 30//////////////////////////////////////////////////////////// 31#include <SFML/Network/Socket.hpp> 32#include <sys/types.h> 33#include <sys/socket.h> 34#include <netinet/in.h> 35#include <netinet/tcp.h> 36#include <arpa/inet.h> 37#include <netdb.h> 38#include <unistd.h> 39 40 41namespace sf 42{ 43namespace priv 44{ 45//////////////////////////////////////////////////////////// 46/// \brief Helper class implementing all the non-portable 47/// socket stuff; this is the Unix version 48/// 49//////////////////////////////////////////////////////////// 50class SocketImpl 51{ 52public : 53 54 //////////////////////////////////////////////////////////// 55 // Types 56 //////////////////////////////////////////////////////////// 57 typedef socklen_t AddrLength; 58 59 //////////////////////////////////////////////////////////// 60 /// \brief Create an internal sockaddr_in address 61 /// 62 /// \param address Target address 63 /// \param port Target port 64 /// 65 /// \return sockaddr_in ready to be used by socket functions 66 /// 67 //////////////////////////////////////////////////////////// 68 static sockaddr_in CreateAddress(unsigned long address, unsigned short port); 69 70 //////////////////////////////////////////////////////////// 71 /// \brief Return the value of the invalid socket 72 /// 73 /// \return Special value of the invalid socket 74 /// 75 //////////////////////////////////////////////////////////// 76 static SocketHandle InvalidSocket(); 77 78 //////////////////////////////////////////////////////////// 79 /// \brief Close and destroy a socket 80 /// 81 /// \param sock Handle of the socket to close 82 /// 83 //////////////////////////////////////////////////////////// 84 static void Close(SocketHandle sock); 85 86 //////////////////////////////////////////////////////////// 87 /// \brief Set a socket as blocking or non-blocking 88 /// 89 /// \param sock Handle of the socket 90 /// \param block New blocking state of the socket 91 /// 92 //////////////////////////////////////////////////////////// 93 static void SetBlocking(SocketHandle sock, bool block); 94 95 //////////////////////////////////////////////////////////// 96 /// Get the last socket error status 97 /// 98 /// \return Status corresponding to the last socket error 99 /// 100 //////////////////////////////////////////////////////////// 101 static Socket::Status GetErrorStatus(); 102}; 103 104} // namespace priv 105 106} // namespace sf 107 108 109#endif // SFML_SOCKETIMPL_HPP