version 0.1.6
[fms.git] / libs / shttpd / io_socket.c
1 /*
2  * Copyright (c) 2004-2005 Sergey Lyubka <valenok@gmail.com>
3  * All rights reserved
4  *
5  * "THE BEER-WARE LICENSE" (Revision 42):
6  * Sergey Lyubka wrote this file.  As long as you retain this notice you
7  * can do whatever you want with this stuff. If we meet some day, and you think
8  * this stuff is worth it, you can buy me a beer in return.
9  */
10
11 #include "defs.h"
12
13 static int
14 read_socket(struct stream *stream, void *buf, size_t len)
15 {
16         assert(stream->chan.sock != -1);
17         return (recv(stream->chan.sock, buf, len, 0));
18 }
19
20 static int
21 write_socket(struct stream *stream, const void *buf, size_t len)
22 {
23         assert(stream->chan.sock != -1);
24         return (send(stream->chan.sock, buf, len, 0));
25 }
26
27 static void
28 close_socket(struct stream *stream)
29 {
30         assert(stream->chan.sock != -1);
31         (void) closesocket(stream->chan.sock);
32 }
33
34 const struct io_class   io_socket =  {
35         "socket",
36         read_socket,
37         write_socket,
38         close_socket
39 };