wangzhengquan
2020-10-10 9ebe80228c7b7cb35ccaeaaa46ccf726bf71d6bd
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
#include "net_mod_socket.h"
#include "socket_io.h"
#include "net_mod_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);
  rio_writen(clientfd, PKG_SEP, strlen(PKG_SEP));
 
  char resp[MAXLINE];
  int ss;
  ss = rio_readpkgb(&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);
}