2009-11-16 19:34:24 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2009 Alistair Riddoch
|
|
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
// $Id$
|
|
|
|
|
|
2011-02-15 09:30:46 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
|
#undef NDEBUG
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
#define DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-11-16 19:34:24 +00:00
|
|
|
#include "server/CommServer.h"
|
|
|
|
|
|
2012-11-23 11:05:59 +00:00
|
|
|
#include "common/CommSocket.h"
|
2010-03-20 17:30:29 +00:00
|
|
|
#include "common/log.h"
|
2011-10-31 12:47:56 +01:00
|
|
|
#include "common/SystemTime.h"
|
2009-11-16 19:34:24 +00:00
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
2010-03-20 17:30:29 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
2009-11-16 19:34:24 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
|
|
class CommFakeSocket : public CommSocket {
|
|
|
|
|
public:
|
|
|
|
|
std::string m_filename;
|
|
|
|
|
int m_fd;
|
|
|
|
|
|
|
|
|
|
CommFakeSocket(CommServer & cs) : CommSocket(cs), m_fd(-1) { }
|
|
|
|
|
|
|
|
|
|
virtual int getFd() const { return -1; }
|
|
|
|
|
|
|
|
|
|
virtual bool isOpen() const { return false; }
|
|
|
|
|
|
|
|
|
|
virtual bool eof() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual int read() {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void dispatch() { }
|
|
|
|
|
|
2012-08-01 19:42:36 +01:00
|
|
|
virtual void disconnect() { }
|
|
|
|
|
|
|
|
|
|
virtual int flush() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-16 19:34:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
|
{
|
2011-10-31 13:04:55 +00:00
|
|
|
CommServer commServer;
|
2009-11-16 19:34:24 +00:00
|
|
|
|
|
|
|
|
int ret = commServer.setup();
|
|
|
|
|
assert(ret == 0);
|
|
|
|
|
|
2011-10-29 05:53:56 -07:00
|
|
|
commServer.poll(true);
|
2009-11-16 19:34:24 +00:00
|
|
|
|
|
|
|
|
CommFakeSocket * cfs = new CommFakeSocket(commServer);
|
|
|
|
|
|
|
|
|
|
assert(ret == 0);
|
|
|
|
|
|
2009-11-20 02:11:31 +00:00
|
|
|
ret = commServer.addSocket(cfs);
|
2009-11-16 19:34:24 +00:00
|
|
|
|
2009-11-20 02:11:31 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
|
commServer.removeSocket(cfs);
|
|
|
|
|
}
|
2009-11-16 19:34:24 +00:00
|
|
|
|
2011-10-29 05:53:56 -07:00
|
|
|
commServer.poll(true);
|
2009-11-16 19:34:24 +00:00
|
|
|
|
2011-10-31 12:47:56 +01:00
|
|
|
commServer.idle(SystemTime(), false);
|
2009-11-16 19:34:24 +00:00
|
|
|
}
|
2010-03-20 17:30:29 +00:00
|
|
|
|
|
|
|
|
// Stub functions
|
|
|
|
|
|
|
|
|
|
CommSocket::CommSocket(CommServer & svr) : m_commServer(svr) { }
|
|
|
|
|
|
|
|
|
|
CommSocket::~CommSocket()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-01 19:42:36 +01:00
|
|
|
int CommSocket::flush()
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-20 17:30:29 +00:00
|
|
|
void log(LogLevel lvl, const std::string & msg)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void logSysError(LogLevel lvl)
|
|
|
|
|
{
|
|
|
|
|
}
|