next up previous contents
Next: 8 Results and Analysis Up: 7 Source Code Presentation Previous: 7.6 Packet Sublayer

7.7 Support Routines

 

7.7.1 makeFragParcel function

struct XUDPFragParcel *makeFragParcel(void);

 1 struct XUDPFragParcel *makeFragParcel(void)
 2 {
 3     static Sequence   parcel=0;
 4     struct XUDPFragParcel *pParcel;
 5 
 6     if ( !(pParcel=malloc(sizeof(struct XUDPFragParcel))))
 7         xudpError("makeFragParcel: Allocating RAM");
 8 
 9     pParcel->parcel=parcel++;
10     pParcel->next=NULL;
11     pParcel->prev=NULL;
12     pParcel->headPacket=NULL;
13     pParcel->end=65535;
14     pParcel->tto=0;
15     pParcel->ack=0;
16     pParcel->timestamp=makeTimestamp();
17 
18     return pParcel;
19 }

7.7.2 makeCmd function

struct XUDPCmd *makeCmd(void);

 1 struct XUDPCmd *makeCmd(void)
 2 {
 3     struct XUDPCmd *pCmd;
 4     
 5     if ( !(pCmd=malloc(sizeof(struct XUDPCmd))))
 6         xudpError("makeCmd: Allocating RAM");
 7 
 8     pCmd->prev=NULL;
 9     pCmd->next=NULL;
10     pCmd->cmd=0;
11     pCmd->timestamp=makeTimestamp();
12     
13     if ( !(pCmd->argbuffer=malloc(MAXARG)) )
14         xudpError("makeCmd: Allocating RAM");
15 
16     pCmd->length=0;
17 
18     return pCmd;
19 }

7.7.3 makeParcel function

struct XUDPParcel *makeParcel(void);

 1 struct XUDPParcel *makeParcel(void)
 2 {
 3     static Sequence      parcel=0;
 4     struct XUDPParcel *pParcel;
 5 
 6     if ( !(pParcel=malloc(sizeof(struct XUDPParcel))))
 7         xudpError("makeParcel: Allocating RAM");
 8 
 9     pParcel->parcel=parcel++;
10     pParcel->tto=0;
11     pParcel->next=NULL;
12     pParcel->prev=NULL;
13     pParcel->buffer=NULL;
14     pParcel->pos=NULL;
15     pParcel->timestamp=makeTimestamp();
16 
17     return pParcel;
18 }

7.7.4 makePacket function

struct XUDPPacket *makePacket(void);

 1 struct XUDPPacket *makePacket(void)
 2 {
 3     struct XUDPPacket *pPacket;
 4 
 5     if ( !(pPacket=malloc(sizeof(struct XUDPPacket))))
 6         xudpError("makePacket: Allocating RAM");
 7 
 8     pPacket->header.sequence=0;
 9     pPacket->header.tto=0;
10     pPacket->length=0;
11     pPacket->next=NULL;
12     pPacket->prev=NULL;
13     pPacket->ack=0;
14     
15     return pPacket;
16 }

7.7.5 insertFragParcel function

int insertFragParcel(struct XUDPFragParcel *pInsertAfter, struct XUDPFragParcel *pParcel);

 1 int insertFragParcel(struct XUDPFragParcel *pInsertAfter, struct XUDPFragParcel *pParcel) 
 2 {
 3     pParcel->next=pInsertAfter->next;
 4     pParcel->prev=pInsertAfter;
 5     pInsertAfter->next=pParcel;
 6     return 0;
 7 }

7.7.6 insertParcel function

int insertParcel(struct XUDPParcel *pInsertAfter, struct XUDPParcel *pParcel);

 1 int insertParcel(struct XUDPParcel *pInsertAfter, struct
 2                     XUDPParcel *pParcel)
 3 {
 4     pParcel->next=pInsertAfter->next;
 5     pParcel->prev=pInsertAfter;
 6     pInsertAfter->next=pParcel;
 7     return 0;
 8 }

7.7.7 insertPacket function

int insertPacket(struct XUDPPacket *pInsertAfter, struct XUDPPacket *pPacket);

 1 int insertPacket(struct XUDPPacket *pInsertAfter, struct XUDPPacket *pPacket) 
 2 {
 3     pPacket->next=pInsertAfter->next;
 4     pPacket->prev=pInsertAfter;
 5     pInsertAfter->next=pPacket;
 6     return 0;
 7 }

7.7.8 deleteFragParcel function

int deleteFragParcel(struct XUDPFragParcel *pParcel);

 1 int deleteFragParcel(struct XUDPFragParcel *pParcel)
 2 {
 3     if (pParcel->prev!=NULL) (pParcel->prev)->next=pParcel->next;
 4     if (pParcel->next!=NULL) (pParcel->next)->prev=pParcel->prev;
 5     free(pParcel);
 6     return 0;
 7 }

7.7.9 deleteCmd function

int deleteCmd(struct XUDPCmd *pCmd);

 1 int deleteCmd(struct XUDPCmd *pCmd)
 2 {
 3     if (pCmd->prev!=NULL) (pCmd->prev)->next=pCmd->next;
 4     if (pCmd->next!=NULL) (pCmd->next)->prev=pCmd->prev;
 5     free(pCmd->argbuffer);
 6     free(pCmd);
 7     return 0;
 8 }

7.7.10 deleteParcel function

int deleteParcel(struct XUDPParcel *pParcel);

 1 int deleteParcel(struct XUDPParcel *pParcel)
 2 {
 3     if (pParcel->prev!=NULL) (pParcel->prev)->next=pParcel->next;
 4     if (pParcel->next!=NULL) (pParcel->next)->prev=pParcel->prev;
 5     free(pParcel->buffer);
 6     free(pParcel);
 7     return 0;
 8 }

7.7.11 deletePacket function

int deletePacket(struct XUDPPacket *pPacket);

 1 int deletePacket(struct XUDPPacket *pPacket)
 2 {
 3     if (pPacket->prev!=NULL) (pPacket->prev)->next=pPacket->next;
 4     if (pPacket->next!=NULL) (pPacket->next)->prev=pPacket->prev;
 5     free(pPacket);
 6     return 0;
 7 }

7.7.12 addFragParcel function

int addFragParcel(struct XUDPFragParcel *pHead, struct XUDPFragParcel *pParcel);

 1 int addFragParcel(struct XUDPFragParcel *pHead, struct XUDPFragParcel *pParcel)
 2 {
 3     struct XUDPFragParcel *pTail;
 4     pTail=pHead;
 5 
 6     while(pTail->next!=NULL) pTail=pTail->next;
 7 
 8     pTail->next=pParcel;
 9     pParcel->prev=pTail;
10     return 0;
11 }

7.7.13 addParcel function

int addParcel(struct XUDPParcel *pHead, struct XUDPParcel *pParcel);

 1 int addParcel(struct XUDPParcel *pHead, struct XUDPParcel *pParcel)
 2 {
 3     struct XUDPParcel *pTail;
 4     pTail=pHead;
 5 
 6     while(pTail->next!=NULL) pTail=pTail->next;
 7 
 8     pTail->next=pParcel;
 9     pParcel->prev=pTail;
10     return 0;
11 }

7.7.14 addCmd function

int addCmd(struct XUDPCmdxs *pHead, struct XUDPCmd *pCmd);

 1 int addCmd(struct XUDPCmd *pHead, struct XUDPCmd *pCmd)
 2 {
 3     struct XUDPCmd *pTail;
 4     pTail=pHead;
 5 
 6     while(pTail->next!=NULL) pTail=pTail->next;
 7 
 8     pTail->next=pCmd;
 9     pCmd->prev=pTail;
10 
11     return 0;
12 }

7.7.15 addPacket function

int addPacket(struct XUDPPacket *pHead, struct XUDPPacket *pPacket);


7.7.16 xudpError function

void xudpError(char *errtext);

 1 int addPacket(struct XUDPPacket *pHead, struct XUDPPacket *pPacket)
 2 {
 3     struct XUDPPacket *pTail;
 4     pTail=pHead;
 5 
 6     while(pTail->next!=NULL) pTail=pTail->next;
 7 
 8     pTail->next=pPacket;
 9     pPacket->prev=pTail;
10     return 0;
11 }

7.7.17 xudpGetFunction function

int xudpGetFunction(struct XUDPHost *xudphost);

 1 int xudpGetFunction(struct XUDPHost *xudphost)
 2 {
 3     char function;
 4     
 5     if (recv(xudphost->fdControl, &function, 1, 0)!=1)
 6      return -1;
 7     
 8     return function;
 9 }

7.7.18 xudpSendFunction function

int xudpSendFunction(struct XUDPHost *xudphost, char fcn, char *data);

 1 int xudpSendFunction(struct XUDPHost *xudphost, char fcn, char *data)
 2 {
 3     int   bytes=0;
 4     int   result;
 5     
 6     if (send(xudphost->fdControl, (char *) &fcn, 1, 0)==1)
 7     {
 8      switch (fcn)   /* Set up the data sizes for all of the functions */
 9      {
10      case F_CONNECTED: bytes=sizeof(struct sockaddr_in); break;
11      case F_ERROR: bytes=1; break;
12      case F_READY: break;
13      case F_BIND: bytes=sizeof(u_short); break;
14      case F_LISTEN: break;
15      case F_ACCEPT: break;
16      case F_CONNECT:
17          bytes=sizeof(struct sockaddr_in);
18          data=(char *)&xudphost->hostaddr;
19          break;
20      case F_SENDAUDIO: bytes=sizeof(u_short); break;
21      case F_SENDVIDEO: bytes=sizeof(u_short); break;
22      case F_RECVVIDEO: bytes=sizeof(u_short); break;
23      case F_RECVAUDIO: bytes=sizeof(u_short); break;
24      case F_CLOSE: break;
25      default: break;
26      }
27 
28      if (bytes>0)
29      {
30          if ((result=streamWrite(xudphost->fdControl, data,
31                                 bytes))!=bytes)
32              xudpError("UNIX Stream Failed");
33      }
34     }
35     else return -1;
36 
37     return bytes;
38 }

7.7.19 streamRead function

int streamRead(int fd, char *buffer, u_int num);

 1 int streamRead(int fd, char *buffer, u_int num)
 2 {
 3     return(recv(fd, buffer, num, 0));
 4 }

7.7.20 streamWrite function

int streamWrite(int fd, char *buffer, u_int num);

 1 int streamWrite(int fd, char *buffer, u_int num)
 2 {
 3     return(send(fd, buffer, num, 0));
 4 }

7.7.21 makeServer_un function

int makeServer_un(struct sockaddr_un *un_addr, char *path);

 1 int makeServer_un(struct sockaddr_un *un_addr, char *path)
 2 {
 3     int fdSocket, un_len;
 4 
 5     bzero((char *)un_addr, sizeof(struct sockaddr_un));
 6      
 7     if ( (fdSocket=socket(AF_UNIX, SOCK_STREAM, 0)) <0)
 8      xudpError("xudp: socket(UNIX)");   /* Opens a UNIX Stream socket */
 9     
10                                 /* Fill out address structure for server */
11     
12     un_addr->sun_family=AF_UNIX;         /* AF_UNIX is the UNIX Domain
13                                               Protocol Family.*/  
14    
15     strcpy(un_addr->sun_path, path); /* Server stream path */
16      
17     un_len=strlen(un_addr->sun_path) + sizeof(un_addr->sun_family);  
18     
19     if (bind(fdSocket, (struct sockaddr *)un_addr, un_len)<0)
20      xudpError("xudpd: Can't bind address");
21 
22     listen(fdSocket, 5);
23 
24     return fdSocket;
25 }

7.7.22 max function

int max(int x, int y);

 1 int max(int x, int y)
 2 {
 3     if (x>y) return x;
 4     else return y;
 5 }

7.7.23 min function

int min(int x, int y);

 1 int min(int x, int y)
 2 {
 3     if (x<y) return x;
 4     else return y;
 5 }

7.7.24 makeTimestamp function

Timestamp makeTimestamp(void);

 1 Timestamp makeTimestamp(void)
 2 {
 3     Timestamp        timestamp;
 4     static long      startsec=0, startusec=0;
 5     struct timeval   timestuff;
 6 
 7     gettimeofday(&timestuff, (struct timezone *) 0);
 8     if (startsec==0)
 9     {
10      startsec=timestuff.tv_sec;
11      startusec=timestuff.tv_usec;
12     }
13     
14     timestuff.tv_sec-=startsec;
15     timestuff.tv_usec-=startusec;
16 
17     timestamp=((timestuff.tv_usec / (GRANULARITY*1000)) +
18             ((timestuff.tv_sec*1000)/GRANULARITY));
19 
20     return timestamp;
21 }


next up previous contents
Next: 8 Results and Analysis Up: 7 Source Code Presentation Previous: 7.6 Packet Sublayer

Mike Andrews
Wed Mar 19 16:07:58 EST 1997