hallo there,
Can anyone help me to look at my fork problems? I can't seem to
work up the piping..the reason i need that for is because i need to
make a counter global to client and server.(once fork start,
counter will reset). This allow me to communicate with my
counter.....pls help and thanks a lot
sim
for ( ; ; ) {
if ( ((connfd=Accept(listenfd, (SA *) &cliaddr,
&clilen)) < 0)&&(myclients[2].pid=0)){
if (errno == EINTR){
continue;
}
else
err_sys("accept error");
}
else if (myclients[2].pid>0)
{
err_quit("Max client");
}
curtime = time (NULL);
loctime = localtime (&curtime);
client_date = asctime (loctime);
//Check The IP and PORT number here//
if(getpeername(connfd, (struct sockaddr *) &cliaddr,
&clilen)>=0)
{
gethostname( hname, sizeof(hname) );
p = gethostbyname( hname );
for (f = 0; p->h_addr_list[f]; ++f) {
(struct in_addr *)ip = p-
h_addr_list[f];
user_ip = p->h_name;
myclients[max_client].ip =
inet_ntoa(cliaddr.sin_addr);
myclients[max_client].port =
ntohs(cliaddr.sin_port);
myclients[max_client].time = client_date;
myclients[max_client].start = curtime;
}
myclients[max_client].pid = getpid();
//printf("client number %d has pid %d \n", max_client, getpid());
//printf("client number %d has ip %s and port %d\n", max_client,
myclients[max_client].ip, myclients[max_client].port);
//printf("client pid number %d has pid: %d ip %s
port %d time %s duration \n", max_client,
myclients[max_client].pid,
myclients[max_client].ip, myclients[max_client]-
.port,myclients[max_client].time,myclients[max_-
client].duration);
}
pipe(pipe1);
childpid = Fork();
max_client++;
if ((childpid == 0)) { // child process //
Close(pipe1[1]); // close listening
socket //
clilen = sizeof(cliaddr); // process
the request
printf("socket is %d\n", connfd);
printf("pipe1[0] is %d and pipe1[1] is
%d\n", pipe1[0], pipe1[1]);
****This is the function where i neeed to
use pipe for
str_echo(connfd,cliaddr,clilen,childpid-
,&mycounter,pipe1[0],pipe1[1],max_clien-
t,wait_time,myclients);
}
else if (childpid >0)
{
Close(pipe1[1]); // parent
closes connected socket //
}
}
}
--
Posted via http://dbforums.com