Migrating Socket to Network interface
This commit is contained in:
parent
bf36a37e45
commit
c8e37f3868
6 changed files with 127 additions and 45 deletions
46
src/main.cpp
46
src/main.cpp
|
|
@ -1,4 +1,5 @@
|
|||
#include "Core/Logger.hpp"
|
||||
#include "Network/Socket.hpp"
|
||||
|
||||
#include <winsock.h>
|
||||
|
||||
|
|
@ -9,51 +10,6 @@ using namespace std;
|
|||
|
||||
Logger log;
|
||||
|
||||
class Network
|
||||
{
|
||||
public:
|
||||
class Socket
|
||||
{
|
||||
public:
|
||||
int winInit()
|
||||
{
|
||||
WSADATA wsaData;
|
||||
int result = WSAStartup( MAKEWORD(2, 2), & wsaData );
|
||||
if (result != 0) log.err("Network.Socket.winInit: Initialization error");
|
||||
|
||||
log.info("Network.Socket.winInit: Socket initialized");
|
||||
|
||||
SOCKET mainSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
if (mainSocket == INVALID_SOCKET) {
|
||||
log.err("Network.Socket.winInit: Fatal error: Error creating socket");
|
||||
log.err(WSAGetLastError());
|
||||
WSACleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
log.info("Network.Socket.winInit: Socket created\n");
|
||||
|
||||
sockaddr_in service;
|
||||
memset( & service, 0, sizeof(service) );
|
||||
service.sin_family = AF_INET;
|
||||
service.sin_addr.s_addr = inet_addr(NET_SOCK_ADDR);
|
||||
service.sin_port = htons(NET_SOCK_PORT);
|
||||
|
||||
log.info("Network.Socket.winInit: Socket configured\n");
|
||||
|
||||
if (bind(mainSocket, (SOCKADDR *) & service, sizeof(service)) == SOCKET_ERROR ) {
|
||||
log.err("Network.Socket.winInit: Fatal error: Bind failed");
|
||||
closesocket(mainSocket);
|
||||
return 1;
|
||||
}
|
||||
|
||||
log.info("Network.Socket.winInit: Socket bound to address " + NET_SOCK_ADDR + " on port " + string to_string(NET_SOCK_PORT) + ". Ready to listen for connections");
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
int main() {
|
||||
log.raw("mcc v0.0.0");
|
||||
Network::Socket socket;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue