/[LeafOK_CVS]/lbbs/src/netio.c
ViewVC logotype

Diff of /lbbs/src/netio.c

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

Revision 1.3 by sysadm, Fri Oct 22 15:20:32 2004 UTC Revision 1.4 by sysadm, Sun Mar 20 17:37:14 2005 UTC
# Line 20  Line 20 
20  #include <sys/socket.h>  #include <sys/socket.h>
21    
22  char  char
23  s_getc(int socket)  s_getc (int socket)
24  {  {
25    char c;    char c;
26    if (recv(socket,&c,1,0)>0)    if (recv (socket, &c, 1, 0) > 0)
27      return c;      return c;
28    else    else
29      return '\0';      return '\0';
30  }  }
31    
32  int  int
33  s_putc(int socket, char c)  s_putc (int socket, char c)
34  {  {
35    int ret;    int ret;
36      
37    ret = send (socket, &c, 1, 0);    ret = send (socket, &c, 1, 0);
38      
39    return ret;    return ret;
40  }  }
41    
42  int  int
43  s_receive(int socket, char* buffer, int buffer_length, char end_str[])  s_receive (int socket, char *buffer, int buffer_length, char end_str[])
44  {  {
45    char buf_str[2048];    char buf_str[2048];
46    int buf_read,total_read;    int buf_read, total_read;
47    int buf_len = 2047;    int buf_len = 2047;
48    
49    if (buf_len+1 > buffer_length)    if (buf_len + 1 > buffer_length)
50      buf_len = buffer_length -1;      buf_len = buffer_length - 1;
51    
52    total_read = 0;    total_read = 0;
53    strcpy(buffer,"");    strcpy (buffer, "");
54    while((buf_read = recv(socket,buf_str,buf_len,0)) > 0)    while ((buf_read = recv (socket, buf_str, buf_len, 0)) > 0)
   {  
     buf_str[buf_read] = '\0';  
     total_read += buf_read;  
     strcat(buffer,buf_str);  
   
     buf_len = buffer_length - total_read - 1;  
     if (buf_len+1 > buffer_length)  
       buf_len = buffer_length -1;  
   
     if (strcmp((buffer + total_read - strlen(end_str)), end_str) == 0)  
       break;  
     //different line-end symbol in different OS  
     if (strcmp(end_str,"\r") == 0)  
55      {      {
56        if (strcmp((buffer + total_read - 2), "\r\n") == 0)        buf_str[buf_read] = '\0';
57          break;        total_read += buf_read;
58          strcat (buffer, buf_str);
59    
60          buf_len = buffer_length - total_read - 1;
61          if (buf_len + 1 > buffer_length)
62            buf_len = buffer_length - 1;
63    
64          if (strcmp ((buffer + total_read - strlen (end_str)), end_str) == 0)
65            break;
66          //different line-end symbol in different OS
67          if (strcmp (end_str, "\r") == 0)
68            {
69              if (strcmp ((buffer + total_read - 2), "\r\n") == 0)
70                break;
71            }
72      }      }
   }  
73    
74    return total_read;    return total_read;
75  }  }
76    
77  int  int
78  s_send(int socket, const char* in_str)  s_send (int socket, const char *in_str)
79  {  {
80    int ret;    int ret;
81    
82    if (in_str != NULL && strlen(in_str) > 0)    if (in_str != NULL && strlen (in_str) > 0)
83    {      {
84      ret = send(socket, in_str, strlen(in_str), 0);        ret = send (socket, in_str, strlen (in_str), 0);
85    }      }
86      
87    return ret;    return ret;
88  }  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1