22 lines
687 B
C++
22 lines
687 B
C++
#include "socket.hpp"
|
|||
|
|
|
||
|
|
void Socket::from_addrinfo(const addrinfo &info, AddrAction action) {
|
||
|
|
s = socket(info.ai_family, info.ai_socktype, info.ai_protocol);
|
||
|
|
if (s == INVALID_SOCKET) throw -1;
|
||
|
|
int result = SOCKET_ERROR;
|
||
|
|
switch (action) {
|
||
|
|
case NO_ACTION:
|
||
|
|
break;
|
||
|
|
case CONNECT:
|
||
|
|
result = connect(s, info.ai_addr, (int)info.ai_addrlen);
|
||
|
|
if (result == SOCKET_ERROR) throw result;
|
||
|
|
break;
|
||
|
|
case BIND:
|
||
|
|
result = bind(s, info.ai_addr, (int)info.ai_addrlen);
|
||
|
|
if (result == SOCKET_ERROR) throw result;
|
||
|
|
result = listen(s, SOMAXCONN);
|
||
|
|
if (result == SOCKET_ERROR) throw result;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|