Back to index

wims  3.65+svn20090927
Functions
socket.c File Reference
#include "options.c"
#include "score.c"
#include "cmd.c"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void errorquit (char *p)
void opensock (void)
void output (int fh)
void sockerror (int type, char *p,...)
void sockok (char *p)
void answer (int fh)

Function Documentation

void answer ( int  fh)

Definition at line 72 of file socket.c.

{
    int t,l, *ip;

    t=read(fh,commbuf,BUFFERLEN-sizeof(int)); if(t<sizeof(int)) {
       bad: sockerror(3,"Daemon socket read error.");
       goto end;
    }
    ip=(int *) commbuf; l=*ip;
    if(l<=0 || l>=BUFFERLEN-sizeof(int)) goto bad;
    while(t<l+sizeof(int)) {
       struct timeval tv;
       fd_set rset;
       int t2;
       tv.tv_sec=0; tv.tv_usec=20*1000;
       FD_ZERO(&rset); FD_SET(fh,&rset);
       if(select(fh+1,&rset,NULL,NULL,&tv)<=0) goto bad;
       t2=read(fh,commbuf+t,l+sizeof(int)-t);
       if(t2<=0 || t2>l+sizeof(int)-t) goto bad;
       t+=t2;
    }
    textbuf[l]=0; textptr=textbuf;
    answerlen=-1;
    if(debugging) debug("> %s",textbuf);
    if(options()>=0) cmd();
    end: chdir(cwd); cwdtype=dir_home; output(fh);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void errorquit ( char *  p)

Definition at line 20 of file socket.c.

{
    error(p); exit(1);
}

Here is the call graph for this function:

void opensock ( void  )

Definition at line 25 of file socket.c.

{
    struct stat st;
    struct sockaddr_un sun;
    if(stat(sockfile,&st)==0) unlink(sockfile);
    commsock=socket(PF_UNIX,SOCK_STREAM,0);
    if(commsock<0) errorquit("Unable to open socket.");
    sun.sun_family=PF_UNIX;
    snprintf(sun.sun_path,sizeof(sun.sun_path),"%s",sockfile);
    if(bind(commsock,(struct sockaddr *)&sun, sizeof(sun))==-1)
      errorquit("Unable to bind to socket file.");
    if(listen(commsock,SOCKET_QUEUE)==-1) errorquit("listen() error.");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void output ( int  fh)

Definition at line 39 of file socket.c.

{
    int l, *ip;
    if(answerlen<0) l=strlen(textbuf); else l=answerlen;
    ip=(int *) commbuf; *ip=l;
    write(fh,commbuf,l+sizeof(int));
    close(fh);
    if(debugging) {
       if(textbuf[0]=='O') debug("%.2s %d bytes.",textbuf,l);
       else debug("%s",textbuf);
    }
}
void sockerror ( int  type,
char *  p,
  ... 
)

Definition at line 52 of file socket.c.

{
    char *estr, buf[MAX_LINELEN+1];
    va_list vp;
    va_start(vp,p);
    vsnprintf(buf,sizeof(buf),p,vp);
    va_end(vp);
    if(errno==0) estr=""; else estr=strerror(errno);
    snprintf(textbuf,BUFFERLEN-16,"ERROR %d\n%s\n%s",type,buf,estr);
}

Here is the caller graph for this function:

void sockok ( char *  p)

Definition at line 63 of file socket.c.

{
    snprintf(textbuf,BUFFERLEN-16,"OK\n%s",p);
}