MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / duk_trans_socket_write_cb

Function duk_trans_socket_write_cb

Source/Utils/duk_trans_socket_unix.c:209–260  ·  view source on GitHub ↗

Duktape debug transport callback: (possibly partial) write. */

Source from the content-addressed store, hash-verified

207
208/* Duktape debug transport callback: (possibly partial) write. */
209duk_size_t duk_trans_socket_write_cb(void *udata, const char *buffer, duk_size_t length) {
210 ssize_t ret;
211
212 (void) udata; /* not needed by the example */
213
214#if defined(DEBUG_PRINTS)
215 fprintf(stderr, "%s: udata=%p, buffer=%p, length=%ld\n",
216 __func__, (void *) udata, (const void *) buffer, (long) length);
217 fflush(stderr);
218#endif
219
220 if (client_sock < 0) {
221 return 0;
222 }
223
224 if (length == 0) {
225 /* This shouldn't happen. */
226 fprintf(stderr, "%s: write request length == 0, closing connection\n",
227 __FILE__);
228 fflush(stderr);
229 goto fail;
230 }
231
232 if (buffer == NULL) {
233 /* This shouldn't happen. */
234 fprintf(stderr, "%s: write request buffer == NULL, closing connection\n",
235 __FILE__);
236 fflush(stderr);
237 goto fail;
238 }
239
240 /* In a production quality implementation there would be a sanity
241 * timeout here to recover from "black hole" disconnects.
242 */
243
244 ret = write(client_sock, (const void *) buffer, (size_t) length);
245 if (ret <= 0 || ret > (ssize_t) length) {
246 fprintf(stderr, "%s: debug write failed, closing connection: %s\n",
247 __FILE__, strerror(errno));
248 fflush(stderr);
249 goto fail;
250 }
251
252 return (duk_size_t) ret;
253
254 fail:
255 if (client_sock >= 0) {
256 (void) close(client_sock);
257 client_sock = -1;
258 }
259 return 0;
260}
261
262duk_size_t duk_trans_socket_peek_cb(void *udata) {
263#if defined(USE_SELECT)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected