I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit f49be252 authored by mpc's avatar mpc Committed by zzz
Browse files

<Nightblade> hmm

parent f9a96126
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,14 @@ Socket::Socket(int type)
{
#ifdef WINSOCK
winsock_startup();
#endif
sock = socket(PF_INET, type, 0);
#ifdef WINSOCK
if (sock == INVALID_SOCKET)
throw Socket_error(sam_winsock_strerror(WSAGetLastError()));
#else
if (sock == -1)
throw Socket_error(strerror(errno));
#endif
}
......@@ -62,7 +70,7 @@ void Socket::winsock_startup(void)
WSADATA wsaData;
int rc = WSAStartup(wVersionRequested, &wsaData);
if (rc != 0)
throw Socket_error("WSAStartup() failed (" + winsock_strerror(rc) +")");
throw Socket_error(winsock_strerror(rc));
if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
winsock_cleanup();
throw Socket_error("Bad Winsock version");
......
......@@ -39,10 +39,15 @@ namespace Libsockthread {
void func(void);
private:
#ifdef WINSOCK
typedef SOCKET socket_t;
void winsock_cleanup(void);
void winsock_startup(void); // throws Socket_error
const char* winsock_strerror(int code);
#else
typedef int socket_t;
#endif
socket_t sock;
};
class Socket_error : public runtime_error {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment