static ssize_t schan_pull_adapter(gnutls_transport_ptr_t transport, void *buff, size_t buff_len) { struct schan_transport *t = (struct schan_transport*)transport; gnutls_session_t s = (gnutls_session_t)schan_session_for_transport(t); int ret = schan_pull(transport, buff, &buff_len); if (ret) { pgnutls_transport_set_errno(s, ret); return -1; } return buff_len; }
/* schan_pull_adapter * Callback registered with SSLSetIOFuncs as the read function for a * session. Reads data from the session connection. Conforms to the * SSLReadFunc type. * * transport - The session connection * buff - The buffer into which to store the read data. Must be at least * *buff_len bytes in length. * *buff_len - On input, the desired length to read. On successful return, * the number of bytes actually read. * * Returns: * noErr on complete success meaning the requested length was successfully * read. * errSSLWouldBlock when the requested length could not be read without * blocking. *buff_len indicates how much was actually read. The * caller should try again if/when they want to read more. * errSSLClosedGraceful when the connection has closed and there's no * more data to be read. * other error code for failure. */ static OSStatus schan_pull_adapter(SSLConnectionRef transport, void *buff, SIZE_T *buff_len) { struct mac_session *s = (struct mac_session*)transport; size_t requested = *buff_len; int status; OSStatus ret; TRACE("(%p/%p, %p, %p/%lu)\n", s, s->transport, buff, buff_len, *buff_len); status = schan_pull(s->transport, buff, buff_len); if (status == 0) { if (*buff_len == 0) { TRACE("Connection closed\n"); ret = errSSLClosedGraceful; } else if (*buff_len < requested) { TRACE("Pulled %lu bytes before would block\n", *buff_len); ret = errSSLWouldBlock; } else { TRACE("Pulled %lu bytes\n", *buff_len); ret = noErr; } } else if (status == EAGAIN) { TRACE("Would block before being able to pull anything\n"); ret = errSSLWouldBlock; } else { FIXME("Unknown status code from schan_pull: %d\n", status); ret = ioErr; } return ret; }