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

Function parent

lib_acl/samples/vstream_popen/main.cpp:92–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92static void parent(int argc acl_unused, char *argv[])
93{
94 const char *myname = "parent";
95 char *command;
96 ACL_ARGV *env = acl_argv_split("name1&value1&name2&����ֵ2&name3&����ֵ4", "&");
97 ACL_VSTREAM *stream;
98 ACL_ARGV *args = acl_argv_alloc(1);
99 char buf[1024];
100 int ret, i;
101
102 acl_lib_init();
103 printf("%s: pid = %d\r\n", myname, getpid());
104 command = argv[0];
105 acl_argv_add(args, command, "-c", NULL);
106
107 stream = acl_vstream_popen(O_RDWR,
108 ACL_VSTREAM_POPEN_ARGV, args->argv,
109 ACL_VSTREAM_POPEN_ENV, env->argv,
110 ACL_VSTREAM_POPEN_END);
111 if (stream == NULL) {
112 acl_msg_error("%s(%d): popen %s error(%s)",
113 myname, __LINE__, command, acl_last_serror());
114 goto error_end;
115 }
116
117 pipe_status(stream);
118
119 printf("%s: open pipe ok\r\n", myname);
120
121 i = 0;
122 while (1) {
123 pipe_status(stream);
124 ret =acl_vstream_fprintf(stream, ">>from server<<\r\n");
125 if (ret == ACL_VSTREAM_EOF) {
126 printf("%s: fprintf to child error(%s)\r\n",
127 myname, acl_last_serror());
128 break;
129 } else
130 printf("%s: fprintf to child ok\r\n", myname);
131
132 printf("%s: begin wait client msg\n", myname);
133 ret = acl_vstream_gets_nonl(stream, buf, sizeof(buf));
134 if (ret == ACL_VSTREAM_EOF) {
135 printf("%s: gets from child error(%s)\r\n",
136 myname, acl_last_serror());
137 break;
138 }
139 buf[ret] = 0;
140 printf("%s: gets from child ok(%s), i=%d\r\n", myname, buf, i++);
141 }
142
143 acl_vstream_pclose(stream);
144
145error_end:
146
147 acl_argv_free(env);
148 acl_argv_free(args);
149 acl_lib_end();

Callers 1

mainFunction · 0.85

Calls 13

acl_argv_splitFunction · 0.85
acl_argv_allocFunction · 0.85
acl_lib_initFunction · 0.85
acl_argv_addFunction · 0.85
acl_vstream_popenFunction · 0.85
acl_msg_errorFunction · 0.85
acl_last_serrorFunction · 0.85
pipe_statusFunction · 0.85
acl_vstream_fprintfFunction · 0.85
acl_vstream_gets_nonlFunction · 0.85
acl_vstream_pcloseFunction · 0.85
acl_argv_freeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…