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

Annotation of /lbbs/src/netio.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Fri Oct 22 15:20:32 2004 UTC (21 years, 4 months ago) by sysadm
Branch: MAIN
Changes since 1.2: +2 -0 lines
Content type: text/x-csrc
*** empty log message ***

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 sysadm 1.3 #include <string.h>
20     #include <sys/socket.h>
21 sysadm 1.1
22     char
23     s_getc(int socket)
24     {
25     char c;
26     if (recv(socket,&c,1,0)>0)
27     return c;
28     else
29     return '\0';
30     }
31    
32     int
33 sysadm 1.2 s_putc(int socket, char c)
34     {
35     int ret;
36    
37     ret = send (socket, &c, 1, 0);
38    
39     return ret;
40     }
41    
42     int
43 sysadm 1.1 s_receive(int socket, char* buffer, int buffer_length, char end_str[])
44     {
45     char buf_str[2048];
46     int buf_read,total_read;
47     int buf_len = 2047;
48    
49     if (buf_len+1 > buffer_length)
50     buf_len = buffer_length -1;
51    
52     total_read = 0;
53     strcpy(buffer,"");
54     while((buf_read = recv(socket,buf_str,buf_len,0)) > 0)
55     {
56     buf_str[buf_read] = '\0';
57     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;
75     }
76    
77     int
78     s_send(int socket, const char* in_str)
79     {
80 sysadm 1.2 int ret;
81    
82 sysadm 1.1 if (in_str != NULL && strlen(in_str) > 0)
83     {
84 sysadm 1.2 ret = send(socket, in_str, strlen(in_str), 0);
85 sysadm 1.1 }
86 sysadm 1.2
87     return ret;
88 sysadm 1.1 }

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