Created empty TCPNetworkManager; needs work, I don't even like the name
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
#include "server.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int, char**) {
|
||||
#ifdef DEBUG
|
||||
cout << "Beginning server" << endl;
|
||||
#endif
|
||||
Server app;
|
||||
try {
|
||||
app.Init();
|
||||
app.Proc();
|
||||
app.Quit();
|
||||
}
|
||||
catch(exception& e) {
|
||||
cerr << "Fatal error: " << e.what() << endl;
|
||||
return 1;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
cout << "Clean exit" << endl;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
+30
-11
@@ -1,19 +1,38 @@
|
||||
CXXFLAGS+=-std=c++11
|
||||
DFLAGS=-DDEBUG
|
||||
#config
|
||||
CXXFLAGS+=-std=c++11 -DDEBUG
|
||||
LIB=-lmingw32 -lSDL_net -lSDLmain -lSDL -lwsock32 -liphlpapi
|
||||
OBJ=
|
||||
SRC=server.cpp
|
||||
|
||||
all: debug
|
||||
#objects
|
||||
OBJDIR=obj
|
||||
OBJ=$(addprefix $(OBJDIR)/,main.o)
|
||||
|
||||
release: $(OBJ)
|
||||
$(CXX) $(CXXFLAGS) $(SRC) $(OBJ) $(LIB)
|
||||
#output
|
||||
OUTDIR=out
|
||||
OUT=$(addprefix $(OUTDIR)/,a)
|
||||
|
||||
debug: $(OBJ)
|
||||
$(CXX) $(CXXFLAGS) $(DFLAGS) $(SRC) $(OBJ) $(LIB)
|
||||
#source
|
||||
SRC=server.cpp tcp_network_manager.cpp
|
||||
|
||||
#targets
|
||||
all: $(OBJ) $(OUT)
|
||||
$(CXX) $(CXXFLAGS) -o $(OUT) $(SRC) $(OBJ) $(LIB)
|
||||
|
||||
$(OBJ): | $(OBJDIR)
|
||||
|
||||
$(OUT): | $(OUTDIR)
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $(OBJDIR)
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir $(OUTDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c -o $(@) $<
|
||||
|
||||
clean:
|
||||
-$(RM) *.o *.a *.exe
|
||||
$(RM) *.o *.a *.exe
|
||||
|
||||
rebuild: clean all
|
||||
|
||||
unit:
|
||||
$(CXX) $(CXXFLAGS) unit.cpp
|
||||
|
||||
+29
-4
@@ -1,8 +1,33 @@
|
||||
#include "server.hpp"
|
||||
|
||||
#include "SDL/SDL.h"
|
||||
#include "SDL_net/SDL_net.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
int SDL_main(int, char**) {
|
||||
return 0;
|
||||
}
|
||||
using namespace std;
|
||||
|
||||
Server::Server() {
|
||||
//
|
||||
}
|
||||
|
||||
Server::~Server() {
|
||||
//
|
||||
}
|
||||
|
||||
void Server::Init() {
|
||||
if (SDLNet_Init()) {
|
||||
throw(runtime_error("Failed to init SDL_net"));
|
||||
}
|
||||
}
|
||||
|
||||
void Server::Proc() {
|
||||
bool running = true;
|
||||
while(running) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
void Server::Quit() {
|
||||
SDLNet_Quit();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef SERVER_HPP_
|
||||
#define SERVER_HPP_
|
||||
|
||||
class Server {
|
||||
public:
|
||||
Server();
|
||||
~Server();
|
||||
|
||||
void Init();
|
||||
void Proc();
|
||||
void Quit();
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
#include "tcp_network_manager.hpp"
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef TCPNETWORKMANAGER_HPP_
|
||||
#define TCPNETWORKMANAGER_HPP_
|
||||
|
||||
#include "SDL_net/SDL_net.h"
|
||||
|
||||
class TCPNetworkManager {
|
||||
public:
|
||||
TCPNetworkManager();
|
||||
~TCPNetworkManager();
|
||||
|
||||
void Init(int maxConnections);
|
||||
void Quit();
|
||||
|
||||
int AcceptConnections();
|
||||
int CheckSockets();
|
||||
|
||||
int Send(int index, const void* data, int len);
|
||||
int SendAll(const void* data, int len);
|
||||
|
||||
int OpenSocket(const char* host, int port);
|
||||
TCPsocket GetSocket(int index);
|
||||
int CloseSocket(int index);
|
||||
|
||||
int GetMaxConnections();
|
||||
int GetCurrentConnections();
|
||||
private:
|
||||
TCPsocket serverSocket;
|
||||
SDLNet_SocketSet socketSet;
|
||||
int maxConnections, currentConnections;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user