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

Annotation of /lbbs/src/netio.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Tue Oct 19 03:28:44 2004 UTC (21 years, 5 months ago) by sysadm
Branch: MAIN
Content type: text/x-csrc
Socket send / receive data function

1 sysadm 1.1 /***************************************************************************
2     netio.c - description
3     -------------------
4     begin : Mon Oct 18 2004
5     copyright : (C) 2004 by Leaflet
6     email : leaflet@leafok.com
7     ***************************************************************************/
8    
9     /***************************************************************************
10     * *
11     * This program is free software; you can redistribute it and/or modify *
12     * it under the terms of the GNU General Public License as published by *
13     * the Free Software Foundation; either version 2 of the License, or *
14     * (at your option) any later version. *
15     * *
16     ***************************************************************************/
17    
18     #include "common.h"
19    
20     char
21     s_getc(int socket)
22     {
23     char c;
24     if (recv(socket,&c,1,0)>0)
25     return c;
26     else
27     return '\0';
28     }
29    
30     int
31     s_receive(int socket, char* buffer, int buffer_length, char end_str[])
32     {
33     char buf_str[2048];
34     int buf_read,total_read;
35     int buf_len = 2047;
36    
37     if (buf_len+1 > buffer_length)
38     buf_len = buffer_length -1;
39    
40     total_read = 0;
41     strcpy(buffer,"");
42     while((buf_read = recv(socket,buf_str,buf_len,0)) > 0)
43     {
44     buf_str[buf_read] = '\0';
45     total_read += buf_read;
46     strcat(buffer,buf_str);
47    
48     buf_len = buffer_length - total_read - 1;
49     if (buf_len+1 > buffer_length)
50     buf_len = buffer_length -1;
51    
52     if (strcmp((buffer + total_read - strlen(end_str)), end_str) == 0)
53     break;
54     //different line-end symbol in different OS
55     if (strcmp(end_str,"\r") == 0)
56     {
57     if (strcmp((buffer + total_read - 2), "\r\n") == 0)
58     break;
59     }
60     }
61    
62     return total_read;
63     }
64    
65     int
66     s_send(int socket, const char* in_str)
67     {
68     if (in_str != NULL && strlen(in_str) > 0)
69     {
70     send(socket, in_str, strlen(in_str), 0);
71     }
72     }

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