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
| #include "net_mod_socket.h"
| #include "socket_io.h"
|
| NetModSocket::NetModSocket(const char *host, int port)
| {
| char portstr[32];
| sprintf(portstr, "%d", port);
| clientfd = Open_clientfd(host, portstr);
| Rio_readinitb(&rio, clientfd);
| }
|
|
| ssize_t NetModSocket::send(void *buf, size_t size) {
| int n = rio_writen(clientfd, buf, size);
|
| char resp[MAXLINE];
| int ss;
| ss = rio_readlineb(&rio, resp, MAXLINE);
| puts(resp);
| return n;
| }
|
| // ssize_t recv(void *buf, size_t len) {
|
| // return rio_readlineb(&rio, buf, MAXLINE);
|
| // }
|
| NetModSocket::~NetModSocket() {
| Close(clientfd);
| }
|
|