MCPcopy Create free account
hub / github.com/acl-dev/acl / vstream_client

Function vstream_client

lib_acl/samples/vstream/main.cpp:98–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98static int vstream_client(void)
99{
100 const char *myname = "vstream_client";
101 ACL_VSTREAM *client;
102 char ebuf[256], buf[4096];
103 int n, dlen = 0;
104
105 printf("addr: %s, timeout: %d\n", addr, timeout);
106 client = acl_vstream_connect(addr, ACL_NON_BLOCKING, timeout, timeout, 1024);
107 if (client == NULL) {
108 printf("%s(%d): connect addr %s error(%s)\n",
109 myname, __LINE__, addr, acl_last_strerror(ebuf, sizeof(ebuf)));
110 return (-1);
111 }
112
113 printf("%s: connect %s ok\r\n", myname, addr);
114 acl_non_blocking(ACL_VSTREAM_SOCK(client), ACL_BLOCKING);
115
116 n = acl_write_wait(ACL_VSTREAM_SOCK(client), 10);
117 if (n < 0) {
118 printf("connect timeout: %s\n", acl_last_serror());
119 goto END;
120 }
121 acl_vstream_fprintf(client, "hello world\n");
122 while (1) {
123 n = acl_vstream_read(client, buf, sizeof(buf));
124 if (n == ACL_VSTREAM_EOF) {
125 printf("read over: %s\n", acl_last_serror());
126 break;
127 }
128 dlen += n;
129 buf[n] = 0;
130 printf("read reply: %s\n", buf);
131 }
132
133END:
134 acl_vstream_close(client);
135 printf("%s: read %d\n", myname, dlen);
136 return (0);
137}
138
139static void usage(const char *procname)
140{

Callers 1

mainFunction · 0.70

Calls 8

acl_vstream_connectFunction · 0.85
acl_last_strerrorFunction · 0.85
acl_non_blockingFunction · 0.85
acl_write_waitFunction · 0.85
acl_last_serrorFunction · 0.85
acl_vstream_fprintfFunction · 0.85
acl_vstream_readFunction · 0.85
acl_vstream_closeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…