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

Contents of /lbbs/src/netio.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Thu Oct 21 17:28:46 2004 UTC (21 years, 5 months ago) by sysadm
Branch: MAIN
Changes since 1.1: +15 -1 lines
Content type: text/x-csrc
*** empty log message ***

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_putc(int socket, char c)
32 {
33 int ret;
34
35 ret = send (socket, &c, 1, 0);
36
37 return ret;
38 }
39
40 int
41 s_receive(int socket, char* buffer, int buffer_length, char end_str[])
42 {
43 char buf_str[2048];
44 int buf_read,total_read;
45 int buf_len = 2047;
46
47 if (buf_len+1 > buffer_length)
48 buf_len = buffer_length -1;
49
50 total_read = 0;
51 strcpy(buffer,"");
52 while((buf_read = recv(socket,buf_str,buf_len,0)) > 0)
53 {
54 buf_str[buf_read] = '\0';
55 total_read += buf_read;
56 strcat(buffer,buf_str);
57
58 buf_len = buffer_length - total_read - 1;
59 if (buf_len+1 > buffer_length)
60 buf_len = buffer_length -1;
61
62 if (strcmp((buffer + total_read - strlen(end_str)), end_str) == 0)
63 break;
64 //different line-end symbol in different OS
65 if (strcmp(end_str,"\r") == 0)
66 {
67 if (strcmp((buffer + total_read - 2), "\r\n") == 0)
68 break;
69 }
70 }
71
72 return total_read;
73 }
74
75 int
76 s_send(int socket, const char* in_str)
77 {
78 int ret;
79
80 if (in_str != NULL && strlen(in_str) > 0)
81 {
82 ret = send(socket, in_str, strlen(in_str), 0);
83 }
84
85 return ret;
86 }

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