1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include <ClanLib/application.h>
#include <ClanLib/core.h>
#include <ClanLib/network.h>
#include <iostream>
#include <list>
#include "ftp.h"
#include "main.h"
char welcome[] = {'2','2','0','h','i','\r','\n'};
std::list<FTPD*> kill_daemon;
bool server_kill;
ClanFTP app;
int ClanFTP::main(int, char**)
{
try
{
CL_SetupCore setup_core;
CL_SetupNetwork setup_network;
CL_ConsoleWindow console("Console");
console.redirect_stdio();
CL_IPAddress ip;
ip.set_port((std::string)"2021");
ftp = new CL_Socket(CL_Socket::tcp);
ftp->bind(ip);
ftp->sig_read_triggered().connect(this,&ClanFTP::conn);
ftp->sig_write_triggered().connect(this,&ClanFTP::conn);
ftp->sig_exception_triggered().connect(this,&ClanFTP::conn);
ftp->listen(1);
std::cout << "FTP server running." << std::endl;
while(1)
{
CL_System::sleep(10);
CL_System::keep_alive();
}
}
catch(CL_Error err)
{
std::cout << err.message << std::endl;
}
catch(...)
{
std::cout << "A non-ClanLib based error occured. Please provide clanlib-devel@clanlib.org with a back-trace/stack-trace." << std::endl;
}
return 0;
}
void ClanFTP::conn()
{
CL_Socket accept = ftp->accept();
accept.send(welcome,sizeof(welcome));
FTPD *temp = new FTPD(accept);
daemon_list.push_back(temp);
// CL_IPAddress ip;
// ip.set_port(2021);
// ftp = new CL_Socket(CL_Socket::tcp);
// ftp->bind(ip);
// ftp->sig_read_triggered().connect(this,&ClanFTP::conn);
// ftp->sig_write_triggered().connect(this,&ClanFTP::conn);
// ftp->sig_exception_triggered().connect(this,&ClanFTP::conn);
// ftp->listen(4);
}
|