/[pengfork]/pengfork/src/p3/p3.c
ViewVC logotype

Diff of /pengfork/src/p3/p3.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by chupa, Mon Sep 16 14:25:53 2002 UTC revision 1.11 by chupa, Sun Dec 1 01:19:07 2002 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2002  Jean-Charles Salzeber <jc@varspool.net>   * Copyright (C) 2002  Jean-Charles Salzeber <jc@varspool.net>
  * Copyright (C) 2001  Stephane Guth (birdy57) <birdy57@multimania.com>  
3   *   *
4   * This file is part of pengfork.   * This file is part of pengfork.
5   *   *
# Line 21  Line 20 
20   *                   *                
21   */   */
22    
23    #include "config.h"
24    
25  #include <sys/types.h>  #include <sys/types.h>
26  #include <netinet/in.h>  #include <netinet/in.h>
27  #include <stdlib.h>  #include <stdlib.h>
28  #include <string.h>  #include <string.h>
29    
30    #include "gettext.h"
31  #include "log.h"  #include "log.h"
32  #include "buffer.h"  #include "buffer.h"
33  #include "utils.h"  #include "utils.h"
# Line 69  p3_register_to_engine (myaccess) Line 71  p3_register_to_engine (myaccess)
71       const access_t *myaccess;       const access_t *myaccess;
72  {  {
73    if (myaccess->is_connected ())    if (myaccess->is_connected ())
74      engine_register (*(myaccess->fd),P3_TIMEOUT , p3_fn);      engine_register (*(myaccess->fd), P3_TIMEOUT, p3_fn);
75    else    else
76      log (LOG_ERR,      log (LOG_ERR,
77           "Unable to register P3 protocol functions, access is not connected\n");           gettext ("Unable to register P3 protocol functions, access is not connected\n"));
78  }  }
79    
80  int  int
81  p3_ready()  p3_ready ()
82  {  {
83    return !win_full(&wsend);    return !win_full (&wsend);
84  }  }
85    
86  void  void
# Line 102  p3_init (bufin, bufout) Line 104  p3_init (bufin, bufout)
104  }  }
105    
106  int  int
107  p3_want_write(out)  p3_want_write (out)
108       buffer_t * out;       buffer_t *out;
109  {  {
110    int i;    int i;
111    char *packet,*p;    char *packet, *p;
112    size_t packet_size;    size_t packet_size;
113      
114    for(i=0;i<wsend.used;i++)    for (i = 0; i < wsend.used; i++)
115      {      {
116        win_get(&wsend, i, &packet, &packet_size);        win_get (&wsend, i, &packet, &packet_size);
117        if( buffer_reserve(out,packet_size) )        if (buffer_reserve (out, packet_size))
118          {          {
119          p=buffer_end(out);            p = buffer_end (out);
120          buffer_alloc(out,packet_size);            buffer_alloc (out, packet_size);
121          memcpy(p, packet, packet_size);            memcpy (p, packet, packet_size);
122          }          }
123        else break;        else
124            break;
125      }      }
126    win_delete(&wsend,i);    win_delete (&wsend, i);
127    return 1;    return 1;
128  }  }
129    
# Line 136  p3_recv (bufin) Line 139  p3_recv (bufin)
139     * Do not try to treat the buffer until we have enough space into the     * Do not try to treat the buffer until we have enough space into the
140     * send window to put some ack and data packets     * send window to put some ack and data packets
141     */     */
142    if(wsend.used <= WINDOW_HIGH)    if (wsend.used <= WINDOW_HIGH)
143      {      {
144        while (p3_extract_packet (bufin, &header, &data, &data_size))        while (p3_extract_packet (bufin, &header, &data, &data_size))
145          {          {
146          p3_treat_packet(header,data,data_size);            p3_treat_packet (header, data, data_size);
147          buffer_free (bufin, data_size + P3_DATA_OFFSET + 1);            buffer_free (bufin, data_size + P3_DATA_OFFSET + 1);
148          }          }
149      }      }
150  }  }
151    
152  void  void
153  p3_timeout(bufin, bufout, timeout)  p3_timeout (bufin, bufout, timeout)
154       buffer_t *bufin;       buffer_t *bufin;
155       buffer_t *bufout;       buffer_t *bufout;
156       int timeout;       int timeout;
157  {  {
158    debug(1,"P3 - timeout notified\n");    debug (1, "P3 - timeout notified\n");
159    if(timeout<10)    if (timeout < 10)
160      {      {
161        if(srv.lastseq != cli.lastack)        if (srv.lastseq != cli.lastack)
162          {          {
163          /* Server has some unacknowledged packets */            /* Server has some unacknowledged packets */
164          p3_put_packet(TYPE_ACK,NULL,0);            p3_put_packet (TYPE_ACK, NULL, 0);
165          }          }
166      }      }
167    else if(timeout < 15)    else if (timeout < 15)
168      {      {
169        if(cli.lastseq != srv.lastack)        if (cli.lastseq != srv.lastack)
170          {          {
171          /* we have some unacknowledged packets */            /* we have some unacknowledged packets */
172          p3_put_packet(TYPE_PING,NULL,0);            p3_put_packet (TYPE_PING, NULL, 0);
173          }          }
174      }      }
175    else if(timeout < 35)    else if (timeout < 35)
176      {      {
177        if(cli.lastseq != srv.lastack)        if (cli.lastseq != srv.lastack)
178          {          {
179          /* we have some unacknowledged packets */            /* we have some unacknowledged packets */
180          p3_put_packet(TYPE_PING,NULL,0);            p3_put_packet (TYPE_PING, NULL, 0);
181          }          }
182      }      }
183    else    else
184      {      {
185        if(cli.lastseq != srv.lastack)        if (cli.lastseq != srv.lastack)
186          {          {
187          /* Always some unacknowledged packets??!!            /* Always some unacknowledged packets??!!
188           * The server seems out or lost             * The server seems out or lost
189           */             */
190            
191          }          }
192      }      }
193    if(nack_sent)    if (nack_sent)
194      {      {
195        /* Server do not have responded to NACK, retry */        /* Server do not have responded to NACK, retry */
196        p3_put_packet(TYPE_NACK,NULL,0);        p3_put_packet (TYPE_NACK, NULL, 0);
197      }      }
198  }  }

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26