File: main.cpp

package info (click to toggle)
clanlib 1.0~svn3827-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 24,600 kB
  • sloc: cpp: 101,591; xml: 6,410; makefile: 1,743; ansic: 463; perl: 424; php: 247; sh: 53
file content (77 lines) | stat: -rw-r--r-- 1,595 bytes parent folder | download | duplicates (7)
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);
}