?? serve.c
字號:
#include <stdio.h>
#include <signal.h>
#include <errno.h>
#include "sock_func.h"
#include "proc_func.h"
void outfunc()
{
printf("serve has been stop !\n");
/*msgctl(msqid , IPC_RMID, 0);*/
exit(0);
}
void timefunc()
{
/*TraceLog_str("accept happen timeout!");*/
alarm(60);
}
void main()
{
int clien , childpid ;
int newsockfd ;
struct sockaddr_in cli_addr ;
int rval ;
int sockfd ;
signal(SIGINT , outfunc ) ;
signal(SIGTERM, outfunc ) ;
signal(SIGALRM, timefunc) ;
printf("tty=%s\n",ttyname());
/*----------------------------*/
/* initialization for SOCKET */
/*----------------------------*/
rval = socket_init( &sockfd ) ;
if ( rval < 0 ) {
return ;
}
/*-------------------------------*/
/* enter the loop for processing */
/*-------------------------------*/
for ( ; ; ) {
clien = sizeof(cli_addr) ;
alarm(60) ;
newsockfd = accept( sockfd , (struct sockaddr *)&cli_addr , &clien ) ;
alarm(0) ;
if ( newsockfd < 0 ) {
TraceLog_str("accept happen error!\n");
return ;
}
childpid = fork();
if ( childpid == -1 ) {
exit(-1) ;
}
else if ( childpid == 0 ) {
/*------------------------*/
/* child process */
/*------------------------*/
close( sockfd ) ;
TraceLog_str("one client has been linked!");
process_request( newsockfd ) ;
shutdown(newsockfd,SHUT_RDWR);
close( newsockfd ) ;
exit(0) ;
}
else {
/*------------------------*/
/* parent process */
/*------------------------*/
close( newsockfd ) ;
wait((int*)0) ;
}
}
/*
kill(childpid , SIGKILL);
shutdown(sockfd,SHUT_RDWR);
close( sockfd );
printf("serve is stop!\n");
*/
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -