-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathio.h
93 lines (69 loc) · 2.51 KB
/
io.h
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* io.h
* XBolo
*
* Created by Robert Chrzanowski.
* Copyright 2004 Robert Chrzanowski. All rights reserved.
*
*/
#ifndef __IO__
#define __IO__
#include <unistd.h>
#include <sys/socket.h>
/*
* Readblock() reads nbytes of file descriptor d into buf. Returns nbytes
* on success and -1 on failure and sets errno.
*/
ssize_t readblock(int d, void *buf, size_t nbytes);
/*
* Writeblock() writes nbytes of buf to file descriptor d. Returns nbytes
* on success and -1 on failure and sets errno.
*/
ssize_t writeblock(int d, const void *buf, size_t nbytes);
/*
* Writestr() writes the string str to the file descriptor d. Returns 0
* on success and -1 on failure and sets errno.
*/
ssize_t writestr(int d, const char *str);
/*
* Sendblock() sends len bytes of msg to socket s. Returns 0
* on success, or -1 on failure and sets errno.
*/
int sendblock(int s, const void *msg, size_t len);
/*
* Sendstr() sends the characters in str including the terminating NUL
* character. Returns 0 on success, or -1 on failure and sets errno.
*/
int sendstr(int s, const char *str);
/*
* Sendblockto() sends len bytes of msg to socket s. Returns 0
* on success, or -1 on failure and sets errno. Changes len to the
* number of bytes sent regardless of success or failure.
*/
//int sendblockto(int s, const void *msg, size_t *len, int flags, const struct sockaddr *to, int tolen);
/*
* Recvblock() attempts to read len bytes to buf from socket s. Returns number of bytes
* received on success, or -1 on failure and sets errno.
*/
ssize_t recvblock(int s, void *buf, size_t len);
/*
* Recvblockpeek() writes len bytes to buf from socket s but does not remove
* them from the buffer. Returns number of bytes received on success, or -1
* on failure and sets errno.
*/
ssize_t recvblockpeek(int s, void *buf, size_t len);
/*
* Recvstr() reads socket s until a terminating NUL character is found and
* allocates a string which is what str is set to. Returns number of bytes
* read including terminating NUL character on success, or -1 on failure and
* sets errno. Caller must free() str when it no longer needs it.
*/
ssize_t recvstr(int s, char **str);
/*
* Recvblockfrom() receives nbytes of socket s into buf. Returns 0
* on success and -1 on failure and sets errno. Changes nbytes to the
* number of bytes received regardless of success or failure.
*/
ssize_t recvblockfrom(int s, void *buf, size_t *len, int flags, struct sockaddr *from, socklen_t *fromlen);
int closesock(int *sock);
#endif /* __IO__ */