Sha256: a772e21c234bcfe23eae60b726223bd0bcd863a844612e54d02ce9ca0bc57f56

Contents?: true

Size: 1.47 KB

Versions: 17

Compression:

Stored size: 1.47 KB

Contents

#ifndef GOSUIMPL_SOCKETS_HPP
#define GOSUIMPL_SOCKETS_HPP

#include <Gosu/Platform.hpp>
#include <boost/utility.hpp>

#ifdef GOSU_IS_WIN
    #include "winsock2.h"
    #define GOSU_SOCK_ERR(code) WSA##code
    namespace Gosu { typedef SOCKET SocketHandle; }
    typedef int socklen_t;
#else
    #include <sys/errno.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <netdb.h>
    #include <sys/ioctl.h> 
    #define GOSU_SOCK_ERR(code) code
    #define INVALID_SOCKET -1
    #define SOCKET_ERROR -1
    #define closesocket close
    #define ioctlsocket ioctl
    namespace Gosu { typedef int SocketHandle; }
#endif

namespace Gosu
{
    // Owns a socket and manages library initialization.
    class Socket : boost::noncopyable
    {
        SocketHandle handle_;

    public:
        Socket();
        ~Socket();

        SocketHandle handle() const;
        void setHandle(SocketHandle value);
        void setBlocking(bool value);

        SocketAddress address() const;
        SocketPort port() const;

        void swap(Socket& other);
    };

    int lastSocketError();
    
    GOSU_NORETURN void throwLastSocketError();
    
    template<typename T>
    T socketCheck(T retVal)
    {
        if (retVal == SOCKET_ERROR &&
            lastSocketError() != GOSU_SOCK_ERR(EWOULDBLOCK))
        {
            throwLastSocketError();
        }
        
        return retVal;
    }
}

#endif

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
gosu-0.7.33 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.32 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.31 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.30 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.29 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.28 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.27.1 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.27 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.26.1 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.26 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.25 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.24 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.23 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.22 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.21 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.20 GosuImpl/Sockets/Sockets.hpp
gosu-0.7.19 GosuImpl/Sockets/Sockets.hpp