/* receive data from the application (sent to us using mywrite()). * the call blocks until data is available. */ size_t stcp_app_recv(mysocket_t sd, void *dst, size_t max_len) { mysock_context_t *ctx = _mysock_get_context(sd); assert(ctx && dst); /* app may have passed in data of arbitrary length; all of it must be * passed down to the transport layer. if it doesn't fit in the specified * buffer, any left over is kept for the next call to app_recv(). */ return _mysock_dequeue_buffer(ctx, &ctx->app_recv_queue, dst, max_len, TRUE); }
int myread(mysocket_t sd, void *buf, size_t buf_len) { mysock_context_t *ctx = _mysock_get_context(sd); int len; MYSOCK_CHECK(ctx != NULL, EBADF); MYSOCK_CHECK(!ctx->listening, EINVAL); assert(!ctx->close_requested); if (ctx->eof) return 0; if ((len = _mysock_dequeue_buffer(ctx, &ctx->app_send_queue, buf, buf_len, TRUE)) == 0) { /* make sure repeated calls to myread() return 0 on EOF */ ctx->eof = TRUE; } return len; }