home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp / src / l / inet-handler / handler / pendingwrites.c < prev    next >
Encoding:
Text File  |  1994-04-05  |  1.2 KB  |  48 lines

  1. /* $Id: pendingwrites.c,v 1.2 1994/01/24 17:33:51 too Exp $
  2.  *
  3.  * Copyright (c) 1993 AmiTCP/IP Group <amitcp-group@hut.fi>
  4.  *
  5.  * Created: Wed Nov 10 13:10:28 1993 too
  6.  * Last modified: Mon Jan 24 19:11:41 1994 too
  7.  */
  8. {
  9.   /*
  10.    * There are some messages that aren't fully sent. Attempt to sent
  11.    * rest of the message.
  12.    */
  13.   For_Each_List_Item(&writelist, struct PendingWrites *, pw, {
  14.     int sent;
  15.     
  16.     if (FD_ISSET(pw->pw_Applport->ap_Sd, wfdsp)) {
  17.       if ((sent = send(pw->pw_Applport->ap_Sd, pw->pw_Start,
  18.                pw->pw_Left, 0)) == pw->pw_Left) {
  19.     /*
  20.      * If all remaining bytes were sent, this pw node becomes
  21.      * obsolete and it is moved to free writes list.
  22.      */
  23.     ReplyPkt(pw->pw_Packet, pw->pw_Len, 0);
  24.     goto clear;
  25.       }
  26.       else {
  27.     if (sent == -1)
  28.       if (Errno() != EWOULDBLOCK) {
  29.         ReplyPkt(pw->pw_Packet, -1, 0); /* -1 == EOF in Write() */
  30.         goto clear;
  31.       }
  32.       else /* set sent to 0 */
  33.         continue;
  34.     pw->pw_Start += sent;
  35.     pw->pw_Left  -= sent;
  36.       }
  37.     }
  38.     continue;
  39.   clear:
  40.     writespending--;   /* identical code 2 times */
  41.     FD_CLR(pw->pw_Applport->ap_Sd, &writefds);
  42.     pw->pw_Applport->ap_Pw = NULL;
  43.     
  44.     Remove(&pw->pw_Link);
  45.     AddTail((struct List *)&freewritelist, &pw->pw_Link);
  46.   });
  47. }
  48.