Some changes to server compatibility

This commit is contained in:
Henrique
2012-07-30 16:40:03 -03:00
parent 4c369bc823
commit c969f5209f
5 changed files with 29 additions and 7 deletions

View File

@@ -25,10 +25,11 @@
#include "declarations.h"
#include <boost/asio.hpp>
#include <framework/luaengine/luaobject.h>
#include <framework/core/timer.h>
#include <framework/core/declarations.h>
class Connection : public stdext::shared_object
class Connection : public LuaObject
{
typedef std::function<void(const boost::system::error_code&)> ErrorCallback;
typedef std::function<void(uint8*, uint16)> RecvCallback;

View File

@@ -26,6 +26,7 @@
#include "declarations.h"
#include "inputmessage.h"
#include "outputmessage.h"
#include "connection.h"
#include <framework/luaengine/luaobject.h>
@@ -41,6 +42,8 @@ public:
bool isConnected();
bool isConnecting();
ConnectionPtr getConnection() { return m_connection; }
void setConnection(const ConnectionPtr& connection) { m_connection = connection; }
void generateXteaKey();
std::vector<int> getXteaKey();

View File

@@ -25,12 +25,17 @@
extern asio::io_service g_ioService;
Server::Server(uint16 port)
Server::Server(int port)
: m_acceptor(g_ioService, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port))
{
}
void Server::acceptNext(const AcceptCallback& acceptCallback)
ServerPtr Server::create(int port)
{
return ServerPtr(new Server(port));
}
void Server::acceptNext()
{
ConnectionPtr connection = ConnectionPtr(new Connection);
connection->m_connecting = true;
@@ -39,6 +44,6 @@ void Server::acceptNext(const AcceptCallback& acceptCallback)
connection->m_connected = true;
connection->m_connecting = false;
}
acceptCallback(connection, error);
callLuaField("onAccept", connection, error.message(), error.value());
});
}

View File

@@ -24,15 +24,17 @@
#define SERVER_H
#include "declarations.h"
#include <framework/luaengine/luaobject.h>
class Server
class Server : public LuaObject
{
typedef std::function<void(ConnectionPtr, const boost::system::error_code&)> AcceptCallback;
public:
Server(uint16 port);
Server(int port);
static ServerPtr create(int port);
void acceptNext(const AcceptCallback& acceptCallback);
void acceptNext();
private:
asio::ip::tcp::acceptor m_acceptor;