Exemplo n.º 1
0
void CFiberConnect::run(void)
{
#if 0
	acl::string serverAddr(m_serverAddr);
	char *addr = serverAddr.c_str();
	char *port_s = strchr(addr, ':');

	ASSERT(port_s && *(port_s + 1));
	*port_s++ = 0;

	struct sockaddr_in sa;
	int len = sizeof(sa);
	memset(&sa, 0, sizeof(sa));
	sa.sin_family = AF_INET;
	sa.sin_port   = htons(atoi(port_s));
	sa.sin_addr.s_addr = inet_addr(addr);

	socket_t sock = acl_fiber_socket(AF_INET, SOCK_STREAM, 0);

	if (acl_fiber_connect(sock, (const struct sockaddr*) &sa, len) < 0)
		printf("connect %s error %s\r\n", m_serverAddr.c_str(),
			acl::last_serror());
	else
		doEcho(sock);

	acl_fiber_close(m_sock);
#else
	acl::socket_stream conn;
	if (conn.open(m_serverAddr, 10, 0) == false)
		printf("connect %s error %s\r\n", m_serverAddr.c_str(),
			acl::last_serror());
	else
		doEcho(conn);
#endif
	m_hWin.OnFiberConnectExit();
	delete this;
}
Exemplo n.º 2
0
/*this is the main routine*/
void doshell()
{
	char line[80];

	/*run forever - the shell shouldn't end*/
	while(1==1)
	{
		/*read in a line*/
		printstring("SHELL>\0");
		readstring(line);

		/*match it against each possible command*/
		/*if the user presses return, ignore it*/
		if (line[0]==0xd)
			continue;
		else if (iscommand(line,"CLS\0")==1)
			doclear();
		else if (iscommand(line,"cls\0")==1)
			doclear();
		else if (iscommand(line,"COPY\0")==1)
			docopy();
		else if (iscommand(line,"copy\0")==1)
			docopy();
		else if (iscommand(line,"CREATE \0")==1)
			docreate(line);
		else if (iscommand(line,"create \0")==1)
			docreate(line);
		else if (iscommand(line,"DELETE \0")==1)
			dodelete(line);
		else if (iscommand(line,"delete \0")==1)
			dodelete(line);
		else if (iscommand(line,"DIR\0")==1)
			dodir();
		else if (iscommand(line,"dir\0")==1)
			dodir();
		else if (iscommand(line,"EXEC \0")==1)
			doexecute(line,1);
		else if (iscommand(line,"exec \0")==1)
			doexecute(line,1);
		else if (iscommand(line,"EXECBACK \0")==1)
			doexecute(line,0);
		else if (iscommand(line,"execback \0")==1)
			doexecute(line,0);
		else if (iscommand(line,"HELP\0")==1)
			dohelp();
		else if (iscommand(line,"help\0")==1)
			dohelp();
		else if (line[0]=='?')
			dohelp();
		else if (iscommand(line,"TYPE \0")==1)
			dotype(line);
		else if (iscommand(line,"type \0")==1)
			dotype(line);
		else if (iscommand(line,"KILL \0")==1)
			dokill(line);
		else if (iscommand(line,"kill \0")==1)
			dokill(line);
		else if (iscommand(line,"mkdir \0")==1)
			domkdir(line);
		else if (iscommand(line,"MKDIR\0")==1)
			domkdir(line);	
		else if (iscommand(line,"FORMAT\0")==1)
			doFormat();	
		else if (iscommand(line,"format\0")==1)
			doFormat();	
		else if (iscommand(line,"remove\0")==1)
			doRemove(line);	
		else if (iscommand(line,"REMOVE\0")==1)
			doRemove(line);	
		else if (iscommand(line,"list\0")==1)
			doList();	
		else if (iscommand(line,"LIST\0")==1)
			doList();	
		else if (iscommand(line,"count\0")==1)
			doCount(line);
		else if (iscommand(line,"WRITE\0")==1)
				doCreateFile(line);	
		else if (iscommand(line,"write\0")==1)
			doCreateFile(line);
		else if (iscommand(line,"READ\0")==1)
				doEcho(line);	
		else if (iscommand(line,"read\0")==1)
			doEcho(line);
		else
			printstring("Command not found\r\n\0");
		printstring("\r\n\0");
	}
}
Exemplo n.º 3
0
int main (int argc, char **argv)
{
	int port = 0;
	const int poolSize = EPOLL_SIZE;
	const int epollSize= EVENT_SIZE;
	struct epoll_event *events;
	struct epoll_event ev;
	int efd=0, sfd=0, cfd=0;
	int rst=0;
	int rvEvents=0;
	int i=0;

	printf ("WEB SERVER v1.0 - build date: %s\n", __DATE__);
	if (argc > 1){
		port = atoi (argv[1]);
	}
	else {
		printf ("usage: $webserver port\n");
		return 0;
	}

	signal (SIGPIPE, SIG_IGN);

	efd = epoll_init (epollSize);
	if (efd < 0) {
		perror (" init_epoll error");
		return 0;
	}

	events = (struct epoll_event *) malloc(sizeof(*events) * poolSize); 
	if (NULL == events) {
		perror (" epoll_event malloc error");
		close(efd);
		return 0;
	}

	sfd = initAcceptSock (port);
	if (sfd < 0) {
		perror (" init_acceptsock error");
		close(efd);
		close(sfd);
		free(events);
		return 0;
	}

	rst = epoll_in_add (efd, sfd);
	if (rst < 0) {
		perror ("epollf_in_add error");
		close(efd);
		close(sfd);
		free(events);
		return 0;
	}

	while (1) 
	{ 
		rvEvents = epoll_wait (efd, events, poolSize, -1); 
		for (i = 0; i < rvEvents; i++)
		{ 
			if (events[i].data.fd == sfd) { 
				cfd = doAccept (efd, sfd);
			} 
			else {
				doEcho (efd, events[i].data.fd);
			} 
		} 
	} 

}