Sha256: a14f2ed4d5aa1975f63e34489ef2dda312281f5d9fc4a5778b3409e502e1fe2d

Contents?: true

Size: 1.53 KB

Versions: 31

Compression:

Stored size: 1.53 KB

Contents

#ifndef GOSUIMPL_SOCKETS_HPP
#define GOSUIMPL_SOCKETS_HPP

#include <Gosu/Platform.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 <unistd.h>
    #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    {
        Socket(const Socket&);
        Socket& operator=(const Socket&);
        
        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

31 entries across 31 versions & 1 rubygems

Version Path
gosu-0.9.2 src/Sockets/Socket.hpp
gosu-0.9.2.pre1 src/Sockets/Socket.hpp
gosu-0.9.1 src/Sockets/Socket.hpp
gosu-0.9.0 src/Sockets/Socket.hpp
gosu-0.9.0.pre1 src/Sockets/Socket.hpp
gosu-0.8.7.2 src/Sockets/Socket.hpp
gosu-0.8.7.1 src/Sockets/Socket.hpp
gosu-0.8.7 src/Sockets/Socket.hpp
gosu-0.8.6 src/Sockets/Socket.hpp
gosu-0.8.6.pre1 src/Sockets/Socket.hpp
gosu-0.8.5 src/Sockets/Socket.hpp
gosu-0.8.5.pre1 src/Sockets/Socket.hpp
gosu-0.8.4 src/Sockets/Socket.hpp
gosu-0.8.3 src/Sockets/Socket.hpp
gosu-0.8.2 src/Sockets/Socket.hpp
gosu-0.8.1 src/Sockets/Socket.hpp
gosu-0.8.0 src/Sockets/Socket.hpp
gosu-0.8.0.pre7 src/Sockets/Socket.hpp
gosu-0.8.0.pre6 src/Sockets/Socket.hpp
gosu-0.8.0.pre5 src/Sockets/Socket.hpp