https://www.pacificsimplicity.ca/blog/libevent-echo-server-tutorial
根据这一篇写一个最简单的demo。然后开始写client。
client调优
client最初的代码如下:
1 #include <sys/socket.h> 2 #include <sys/un.h> 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <unistd.h> 6 #include <sys/socket.h> 7 #include <fcntl.h> 8 #include <errno.h> 9 10 int main(int argc, char *argv[]) { 11 struct sockaddr_un addr; 12 int fd,rc; 13 14 if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { 15 perror("socket error"); 16 exit(-1); 17 } 18 19 const char *socket_path = "/tmp/mysocket"; 20 memset(&addr, 0, sizeof(addr)); 21 addr.sun_family = AF_UNIX; 22 strcpy(addr.sun_path, socket_path); 23 24 if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { 25 perror("connect error"); 26 exit(-1); 27 } 28 29 char sendbuf[8145] = {0}; 30 rc = 8145; 31 32 { 33 if (write(fd, sendbuf, rc) != rc) { 34 if (rc > 0) fprintf(stderr,"partial write"); 35 else { 36 perror("write error"); 37 exit(-1); 38 } 39 } 40 } 41 42 43 char buf[1024] = {0}; 44 45 while ((rc = read(fd, buf, 1024)) > 0) { 46 buf[rc] = '