/* $Id: pendingwrites.c,v 1.1 1993/11/17 12:21:51 too Exp $
 *
 * Copyright (c) 1993 AmiTCP/IP Group <amitcp-group@hut.fi>
 *
 * Created: Wed Nov 10 13:10:28 1993 too
 * Last modified: Wed Nov 17 14:19:00 1993 too
 */
{
  /*
   * There are some messages that aren't fully sent. Attempt to sent
   * rest of the message.
   */
  For_Each_List_Item(&writelist, struct PendingWrites *, pw, {
    int sent;
    
    if (FD_ISSET(pw->pw_Applport->ap_Sd, wfdsp)) {
      if ((sent = send(pw->pw_Applport->ap_Sd, pw->pw_Start,
		       pw->pw_Left, 0)) == pw->pw_Left) {
	/*
	 * If all remaining bytes were sent, this pw node becomes
	 * obsolete and it is moved to free writes list.
	 */
	ReplyPkt(pw->pw_Packet, pw->pw_Len, 0);
	
	writespending--;   /* identical code 2 times */
	FD_CLR(pw->pw_Applport->ap_Sd, &writefds);
	pw->pw_Applport->ap_Pw = NULL;
	
	Remove(&pw->pw_Link);
	AddTail((struct List *)&freewritelist, &pw->pw_Link);
      }
      else {
	pw->pw_Start += sent;
	pw->pw_Left  -= sent;
      }
    }
  });
}
