socket_stream& socket_stream::set_tcp_sendbuf(int size) { ACL_SOCKET sock = sock_handle(); if (sock == ACL_SOCKET_INVALID) { logger_error("invalid socket handle"); return *this; } acl_tcp_set_sndbuf(sock, size); return *this; }
static void run_client(const char *addr, const char *filename) { char *request = acl_vstream_loadfile(filename); ACL_VSTREAM *client; int ret; char buf[1024]; if (request == NULL) { printf("load file(%s) error(%s)\n", filename, acl_last_serror()); return; } client = acl_vstream_connect(addr, ACL_BLOCKING, 0, 0, 4096); if (client == NULL) { printf("connect addr(%s) error(%s)\n", addr, acl_last_serror()); acl_myfree(request); return; } acl_tcp_set_sndbuf(ACL_VSTREAM_SOCK(client), 10); if (acl_vstream_writen(client, request, strlen(request)) == ACL_VSTREAM_EOF) { printf("write to addr(%s) error(%s)\n", addr, acl_last_serror()); acl_vstream_close(client); acl_myfree(request); return; } memset(buf, 0, sizeof(buf)); while (1) { ret = acl_vstream_read(client, buf, sizeof(buf) - 1); if (ret == ACL_VSTREAM_EOF) break; buf[ret] = 0; usleep(100000); printf(">>>%s\n", buf); } printf(">>>last data(%s)\n", buf); acl_vstream_close(client); acl_myfree(request); }