-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio_socket.c
46 lines (39 loc) · 1.07 KB
/
io_socket.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* Copyright (c) 2004-2005 Sergey Lyubka <[email protected]>
* All rights reserved
*
* "THE BEER-WARE LICENSE" (Revision 42):
* Sergey Lyubka wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return.
*/
#include "defs.h"
static int read_socket(struct stream *stream, void *buf, size_t len)
{
int n;
assert(stream->chan.sock != -1);
// return (recv(stream->chan.sock, buf, len, 0));
n = recv(stream->chan.sock, buf, len, 0);
MY_DEBUG("n=%d\n", n);
return n;
}
static int write_socket(struct stream *stream, const void *buf, size_t len)
{
int n;
assert(stream->chan.sock != -1);
// return (send(stream->chan.sock, buf, len, 0));
n = send(stream->chan.sock, buf, len, 0);
MY_DEBUG("n=%d\n", n);
return n;
}
static void close_socket(struct stream *stream)
{
assert(stream->chan.sock != -1);
(void) closesocket(stream->chan.sock);
}
const struct io_class _shttpd_io_socket = {
"socket",
read_socket,
write_socket,
close_socket
};