Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Checks for new connections via accept() and loads them into sock_t linked list.
- void getnewconn (void)
- {
- struct sockaddr_storage tempAddr;
- int tempSock;
- static sock_t *slnext = NULL;
- // if slnext is NULL, we need to allocate some more memory for a new one.
- // After using up this new one, we set it back to NULL.
- if (!slnext)
- {
- slnext = (sock_t *) malloc (sizeof (sock_t));
- memset (slnext, 0, sizeof (sock_t));
- }
- if ((tempSock = accept (mastersock, (struct sockaddr *)&tempAddr, sizeof(struct sockaddr_storage))) < 0)
- return; // Not this time. D:
- else // YES A NEW CLIENT
- {
- // Fill it out, then put it in the linked list.
- if (!sltail) sltail = slnext; // :|
- slnext.s = tempSock;
- slnext.addr = (struct sockaddr) tempAddr;
- slhead.next = slnext;
- slnext.prev = slhead;
- slnext.next = NULL;
- slhead = slnext;
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement