WEB开发网
开发学院手机开发Android 开发 Android 中的微型云 阅读

Android 中的微型云

 2010-04-09 05:40:00 来源:WEB开发网   
核心提示:"); exit(0); } strcpy((char*) thePort, argv[1]); port=atoi((char*) thePort); if(port < 0 || port > 60000)
");
exit(0);
}
strcpy((char*) thePort, argv[1]);
port=atoi((char*) thePort);

if(port < 0 || port > 60000)
aclog(ERROR, "Invalid port number (try 1 --> 60000)", argv[1], 0);

if(chdir(argv[2]) == -1)
{
printf("ERROR: Invalid directory %s ", argv[2]);
exit(4);
}
}

if(fork() != 0)
return 0;

signal(SIGCHLD, SIG_IGN);
signal(SIGHUP, SIG_IGN);

for(i=0; i<32; i++)
close(i);

setpgrp();

aclog(LOG, "Cloud Port/PID=", (char*) thePort, getpid());

if((listenfd=socket(AF_INET, SOCK_STREAM, 0)) < 0)
aclog(ERROR, "syscall", "socket", 0);

serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(port);

if(bind(listenfd, (struct sockaddr*) &serv_addr,
sizeof(serv_addr)) < 0)
aclog(ERROR, "syscall", "bind", 0);

if(listen(listenfd, 64) <0)
aclog(ERROR, "syscall", "listen", 0);

for(hit=1; ;hit++)
{
length=sizeof(cli_addr);

if((socketfd=accept(listenfd,
(struct sockaddr*) &cli_addr,
(socklen_t*) &length)) < 0)
aclog(ERROR, "syscall", "accept", 0);

if((pid=fork()) < 0)
{
aclog(ERROR, "syscall", "fork", 0);
}
else
{
if(pid == 0)
{
close(listenfd);
child(socketfd, hit);
}
else
{
close(socketfd);
}
}
}
}

上一页  12 13 14 15 16 17 18 19 20 21 22  下一页

Tags:Android 微型

编辑录入:coldstar [复制链接] [打 印]
赞助商链接