aboutsummaryrefslogtreecommitdiff
path: root/libssh/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'libssh/socket.c')
-rw-r--r--libssh/socket.c181
1 files changed, 0 insertions, 181 deletions
diff --git a/libssh/socket.c b/libssh/socket.c
index 8ebf360..9706d13 100644
--- a/libssh/socket.c
+++ b/libssh/socket.c
@@ -560,30 +560,6 @@ int ssh_socket_completewrite(ssh_socket s, const void *buffer, uint32_t len) {
}
/** \internal
- * \brief buffered read of data (complete)
- * \returns SSH_OK or SSH_ERROR.
- * \returns SSH_AGAIN in nonblocking mode
- */
-int ssh_socket_read(ssh_socket s, void *buffer, int len){
- ssh_session session = s->session;
- int rc = SSH_ERROR;
-
- enter_function();
-
- rc = ssh_socket_wait_for_data(s, s->session, len);
- if (rc != SSH_OK) {
- leave_function();
- return rc;
- }
-
- memcpy(buffer, buffer_get_rest(s->in_buffer), len);
- buffer_pass_bytes(s->in_buffer, len);
-
- leave_function();
- return SSH_OK;
-}
-
-/** \internal
* \brief buffered write of data
* \returns SSH_OK, or SSH_ERROR
* \warning has no effect on socket before a flush
@@ -600,163 +576,6 @@ int ssh_socket_write(ssh_socket s, const void *buffer, int len) {
/** \internal
- * \brief wait for data on socket
- * \param s socket
- * \param session the ssh session
- * \param len number of bytes to be read
- * \returns SSH_OK bytes are available on socket
- * \returns SSH_AGAIN need to call later for data
- * \returns SSH_ERROR error happened
- */
-int ssh_socket_wait_for_data(ssh_socket s, ssh_session session, uint32_t len) {
- char buffer[4096] = {0};
- char *buf = NULL;
- int except;
- int can_write;
- int to_read;
- int r;
-
- enter_function();
-
- to_read = len - buffer_get_rest_len(s->in_buffer);
-
- if (to_read <= 0) {
- leave_function();
- return SSH_OK;
- }
-
- if (session->blocking) {
- buf = malloc(to_read);
- if (buf == NULL) {
- leave_function();
- return SSH_ERROR;
- }
-
- r = ssh_socket_completeread(session->socket,buf,to_read);
- if (r == SSH_ERROR || r == 0) {
- ssh_set_error(session, SSH_FATAL,
- (r == 0) ? "Connection closed by remote host" :
- "Error reading socket");
- ssh_socket_close(session->socket);
- session->alive = 0;
- SAFE_FREE(buf);
-
- leave_function();
- return SSH_ERROR;
- }
-
- if (buffer_add_data(s->in_buffer,buf,to_read) < 0) {
- SAFE_FREE(buf);
- leave_function();
- return SSH_ERROR;
- }
-
- SAFE_FREE(buf);
-
- leave_function();
- return SSH_OK;
- }
-
- /* nonblocking read */
- do {
- /* internally sets data_to_read */
- r = ssh_socket_poll(s, &can_write, &except);
- if (r < 0 || !s->data_to_read) {
- leave_function();
- return SSH_AGAIN;
- }
-
- /* read as much as we can */
- if (ssh_socket_is_open(session->socket)) {
- r = ssh_socket_unbuffered_read(session->socket, buffer, sizeof(buffer));
- } else {
- r = -1;
- }
-
- if (r <= 0) {
- ssh_set_error(session, SSH_FATAL,
- (r == 0) ? "Connection closed by remote host" :
- "Error reading socket");
- ssh_socket_close(session->socket);
- session->alive = 0;
-
- leave_function();
- return SSH_ERROR;
- }
-
- if (buffer_add_data(s->in_buffer,buffer, (uint32_t) r) < 0) {
- leave_function();
- return SSH_ERROR;
- }
- } while(buffer_get_rest_len(s->in_buffer) < len);
-
- leave_function();
- return SSH_OK;
-}
-
-/* ssh_socket_poll */
-/** @brief polls the socket for activity
- * @bug this function should disappear in favor of the new polling mechanism
- */
-int ssh_socket_poll(ssh_socket s, int *writeable, int *except) {
- ssh_session session = s->session;
- ssh_pollfd_t fd[2];
- int rc = -1;
- int n_fd;
- enter_function();
-
- if (!ssh_socket_is_open(s)) {
- *except = 1;
- *writeable = 0;
- return 0;
- }
- if(s->fd_in == s->fd_out){
- n_fd=1;
- } else {
- n_fd=2;
- }
- fd[0].fd = s->fd_in;
- fd[0].events = 0;
-
- if (!s->data_to_read) {
- fd[0].events |= POLLIN;
- }
-
- if(n_fd == 2){
- fd[1].fd=s->fd_out;
- fd[1].events = 0;
- }
-
- if (!s->data_to_write) {
- fd[n_fd - 1].events |= POLLOUT;
- }
-
- /* Make the call, and listen for errors */
- rc = ssh_poll(fd, n_fd, 0);
- if (rc < 0) {
- ssh_set_error(session, SSH_FATAL, "poll(): %s", strerror(errno));
- leave_function();
- return -1;
- }
-
- if (!s->data_to_read) {
- s->data_to_read = fd[0].revents & POLLIN;
- }
- if (!s->data_to_write) {
- s->data_to_write = fd[n_fd - 1].revents & POLLOUT;
- }
- if (!s->data_except) {
- s->data_except = fd[0].revents & POLLERR;
- }
-
- *except = s->data_except;
- *writeable = s->data_to_write;
-
- leave_function();
- return (s->data_to_read || (buffer_get_rest_len(s->in_buffer) > 0));
-}
-
-/** \internal
* \brief starts a nonblocking flush of the output buffer
*
*/