chiark / gitweb /
lib/uaudio-pulseaudio.c: Rewrite using the asynchronous API.
[disorder] / lib / socketio.h
CommitLineData
aa846a75
RK
1/*
2 * This file is part of DisOrder
3 * Copyright (C) 2013 Richard Kettlewell
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18/** @file lib/socketio.h
19 * @brief Buffered socket I/O
20 */
21#ifndef SOCKETIO_H
22# define SOCKETIO_H
23
24#define SOCKETIO_BUFFER 4096
25
26struct socketio {
27 SOCKET sd;
28 char *inputptr, *inputlimit;
29 size_t outputused;
30 int error;
31 char input[SOCKETIO_BUFFER];
32 char output[SOCKETIO_BUFFER];
33};
34
35void socketio_init(struct socketio *sio, SOCKET sd);
36int socketio_write(struct socketio *sio, const void *buffer, size_t n);
37int socketio_getc(struct socketio *sio);
38int socketio_flush(struct socketio *sio);
39void socketio_close(struct socketio *sio);
40
41static inline int socketio_error(struct socketio *sio) {
42 return sio->error > 0 ? sio->error : 0;
43}
44
45static inline int socketio_eof(struct socketio *sio) {
46 return sio->error == -1;
47}
48
49#endif