mirror of
				https://github.com/libssh2/libssh2.git
				synced 2025-11-03 22:13:11 +03:00 
			
		
		
		
	I cut out the poll_socket argument from the protos for_libssh2_packet_askv()
and _libssh2_packet_ask() since they are internal and nothing in the code base uses that functionality == simplicity with no drawbacks!
This commit is contained in:
		@@ -304,12 +304,12 @@ libssh2_channel_open_ex(LIBSSH2_SESSION * session, const char *channel_type,
 | 
				
			|||||||
        while ((_libssh2_packet_ask(session, SSH_MSG_CHANNEL_DATA,
 | 
					        while ((_libssh2_packet_ask(session, SSH_MSG_CHANNEL_DATA,
 | 
				
			||||||
                                    &session->open_data,
 | 
					                                    &session->open_data,
 | 
				
			||||||
                                    &session->open_data_len, 1,
 | 
					                                    &session->open_data_len, 1,
 | 
				
			||||||
                                    channel_id, 4, 0) >= 0)
 | 
					                                    channel_id, 4) >= 0)
 | 
				
			||||||
               ||
 | 
					               ||
 | 
				
			||||||
               (_libssh2_packet_ask(session, SSH_MSG_CHANNEL_EXTENDED_DATA,
 | 
					               (_libssh2_packet_ask(session, SSH_MSG_CHANNEL_EXTENDED_DATA,
 | 
				
			||||||
                                    &session->open_data,
 | 
					                                    &session->open_data,
 | 
				
			||||||
                                    &session->open_data_len, 1,
 | 
					                                    &session->open_data_len, 1,
 | 
				
			||||||
                                    channel_id, 4, 0) >= 0)) {
 | 
					                                    channel_id, 4) >= 0)) {
 | 
				
			||||||
            LIBSSH2_FREE(session, session->open_data);
 | 
					            LIBSSH2_FREE(session, session->open_data);
 | 
				
			||||||
            session->open_data = NULL;
 | 
					            session->open_data = NULL;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -1511,18 +1511,24 @@ libssh2_channel_read_ex(LIBSSH2_CHANNEL * channel, int stream_id, char *buf,
 | 
				
			|||||||
        rc = 1; /* set to >0 to let the while loop start */
 | 
					        rc = 1; /* set to >0 to let the while loop start */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* process all pending incoming packets */
 | 
					        /* process all pending incoming packets */
 | 
				
			||||||
        while (rc > 0)
 | 
					        while (rc > 0) {
 | 
				
			||||||
            rc = _libssh2_packet_read(session);
 | 
					            rc = _libssh2_packet_read(session);
 | 
				
			||||||
 | 
					            if(channel->session->socket_block)
 | 
				
			||||||
 | 
					                /* we can't loop in blocking mode as then we might get stuck
 | 
				
			||||||
 | 
					                   in recv() */
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ((rc < 0) && (rc != PACKET_EAGAIN))
 | 
					        if ((rc < 0) && (rc != PACKET_EAGAIN))
 | 
				
			||||||
            return -1;
 | 
					            return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        channel->read_state = libssh2_NB_state_created;
 | 
					        channel->read_state = libssh2_NB_state_created;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    else if(!channel->session->socket_block) {
 | 
				
			||||||
        /* We're not in the idle state, but in order to "even out" the network
 | 
					        /* We're not in the idle state, but in order to "even out" the network
 | 
				
			||||||
           readings we do a single shot read here as well. Tests prove that
 | 
					           readings we do a single shot read here as well. Tests prove that
 | 
				
			||||||
           this way produces faster transfers. */
 | 
					           this way produces faster transfers. But in blocking mode we can't
 | 
				
			||||||
 | 
					           do it. */
 | 
				
			||||||
        rc = _libssh2_packet_read(session);
 | 
					        rc = _libssh2_packet_read(session);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* ignore PACKET_EAGAIN but return failure for the rest */
 | 
					        /* ignore PACKET_EAGAIN but return failure for the rest */
 | 
				
			||||||
@@ -1658,7 +1664,15 @@ libssh2_channel_read_ex(LIBSSH2_CHANNEL * channel, int stream_id, char *buf,
 | 
				
			|||||||
        _libssh2_debug(session, LIBSSH2_DBG_CONN,
 | 
					        _libssh2_debug(session, LIBSSH2_DBG_CONN,
 | 
				
			||||||
                       "channel_read() filled %d adjusted %d",
 | 
					                       "channel_read() filled %d adjusted %d",
 | 
				
			||||||
                       bytes_read, buflen);
 | 
					                       bytes_read, buflen);
 | 
				
			||||||
 | 
					        if(!channel->session->socket_block)
 | 
				
			||||||
 | 
					            /* while not blocking, we can continue in 'created' state to drain
 | 
				
			||||||
 | 
					               the already read packages first before starting to empty the
 | 
				
			||||||
 | 
					               socket further */
 | 
				
			||||||
            channel->read_state = libssh2_NB_state_created;
 | 
					            channel->read_state = libssh2_NB_state_created;
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					            /* in blocking mode we don't know if there's more to read so we need
 | 
				
			||||||
 | 
					               to make it more careful and go back to idle */
 | 
				
			||||||
 | 
					            channel->read_state = libssh2_NB_state_idle;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return bytes_read;
 | 
					    return bytes_read;
 | 
				
			||||||
@@ -2137,10 +2151,10 @@ libssh2_channel_free(LIBSSH2_CHANNEL * channel)
 | 
				
			|||||||
    /* Clear out packets meant for this channel */
 | 
					    /* Clear out packets meant for this channel */
 | 
				
			||||||
    _libssh2_htonu32(channel_id, channel->local.id);
 | 
					    _libssh2_htonu32(channel_id, channel->local.id);
 | 
				
			||||||
    while ((_libssh2_packet_ask(session, SSH_MSG_CHANNEL_DATA, &data,
 | 
					    while ((_libssh2_packet_ask(session, SSH_MSG_CHANNEL_DATA, &data,
 | 
				
			||||||
                                &data_len, 1, channel_id, 4, 0) >= 0)
 | 
					                                &data_len, 1, channel_id, 4) >= 0)
 | 
				
			||||||
           ||
 | 
					           ||
 | 
				
			||||||
           (_libssh2_packet_ask(session, SSH_MSG_CHANNEL_EXTENDED_DATA, &data,
 | 
					           (_libssh2_packet_ask(session, SSH_MSG_CHANNEL_EXTENDED_DATA, &data,
 | 
				
			||||||
                                &data_len, 1, channel_id, 4, 0) >= 0)) {
 | 
					                                &data_len, 1, channel_id, 4) >= 0)) {
 | 
				
			||||||
        LIBSSH2_FREE(session, data);
 | 
					        LIBSSH2_FREE(session, data);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1167,14 +1167,14 @@ int _libssh2_packet_ask(LIBSSH2_SESSION * session, unsigned char packet_type,
 | 
				
			|||||||
                        unsigned char **data, unsigned long *data_len,
 | 
					                        unsigned char **data, unsigned long *data_len,
 | 
				
			||||||
                        unsigned long match_ofs,
 | 
					                        unsigned long match_ofs,
 | 
				
			||||||
                        const unsigned char *match_buf,
 | 
					                        const unsigned char *match_buf,
 | 
				
			||||||
                        unsigned long match_len, int poll_socket);
 | 
					                        unsigned long match_len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int _libssh2_packet_askv(LIBSSH2_SESSION * session,
 | 
					int _libssh2_packet_askv(LIBSSH2_SESSION * session,
 | 
				
			||||||
                         const unsigned char *packet_types,
 | 
					                         const unsigned char *packet_types,
 | 
				
			||||||
                         unsigned char **data, unsigned long *data_len,
 | 
					                         unsigned char **data, unsigned long *data_len,
 | 
				
			||||||
                         unsigned long match_ofs,
 | 
					                         unsigned long match_ofs,
 | 
				
			||||||
                         const unsigned char *match_buf,
 | 
					                         const unsigned char *match_buf,
 | 
				
			||||||
                         unsigned long match_len, int poll_socket);
 | 
					                         unsigned long match_len);
 | 
				
			||||||
int _libssh2_packet_require(LIBSSH2_SESSION * session,
 | 
					int _libssh2_packet_require(LIBSSH2_SESSION * session,
 | 
				
			||||||
                            unsigned char packet_type, unsigned char **data,
 | 
					                            unsigned char packet_type, unsigned char **data,
 | 
				
			||||||
                            unsigned long *data_len, unsigned long match_ofs,
 | 
					                            unsigned long *data_len, unsigned long match_ofs,
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										45
									
								
								src/packet.c
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								src/packet.c
									
									
									
									
									
								
							@@ -964,22 +964,10 @@ int
 | 
				
			|||||||
_libssh2_packet_ask(LIBSSH2_SESSION * session, unsigned char packet_type,
 | 
					_libssh2_packet_ask(LIBSSH2_SESSION * session, unsigned char packet_type,
 | 
				
			||||||
                    unsigned char **data, unsigned long *data_len,
 | 
					                    unsigned char **data, unsigned long *data_len,
 | 
				
			||||||
                    unsigned long match_ofs, const unsigned char *match_buf,
 | 
					                    unsigned long match_ofs, const unsigned char *match_buf,
 | 
				
			||||||
                    unsigned long match_len, int poll_socket)
 | 
					                    unsigned long match_len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    LIBSSH2_PACKET *packet = session->packets.head;
 | 
					    LIBSSH2_PACKET *packet = session->packets.head;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (poll_socket) {
 | 
					 | 
				
			||||||
        /*
 | 
					 | 
				
			||||||
         * XXX CHECK ***
 | 
					 | 
				
			||||||
         * When "poll_socket" is "1" libhss2_packet_read() can return
 | 
					 | 
				
			||||||
         * PACKET_EAGAIN.  I am not sure what should happen, but internally
 | 
					 | 
				
			||||||
         * there is only one location that might do so, libssh2_packet_askv_ex()
 | 
					 | 
				
			||||||
         */
 | 
					 | 
				
			||||||
        libssh2pack_t rc = _libssh2_packet_read(session);
 | 
					 | 
				
			||||||
        if ((rc < 0) && !packet) {
 | 
					 | 
				
			||||||
            return rc;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    _libssh2_debug(session, LIBSSH2_DBG_TRANS,
 | 
					    _libssh2_debug(session, LIBSSH2_DBG_TRANS,
 | 
				
			||||||
                   "Looking for packet of type: %d", (int) packet_type);
 | 
					                   "Looking for packet of type: %d", (int) packet_type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1026,20 +1014,14 @@ _libssh2_packet_askv(LIBSSH2_SESSION * session,
 | 
				
			|||||||
                     unsigned char **data, unsigned long *data_len,
 | 
					                     unsigned char **data, unsigned long *data_len,
 | 
				
			||||||
                     unsigned long match_ofs,
 | 
					                     unsigned long match_ofs,
 | 
				
			||||||
                     const unsigned char *match_buf,
 | 
					                     const unsigned char *match_buf,
 | 
				
			||||||
                     unsigned long match_len, int poll_socket)
 | 
					                     unsigned long match_len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int i, packet_types_len = strlen((char *) packet_types);
 | 
					    int i, packet_types_len = strlen((char *) packet_types);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for(i = 0; i < packet_types_len; i++) {
 | 
					    for(i = 0; i < packet_types_len; i++) {
 | 
				
			||||||
        /*
 | 
					 | 
				
			||||||
         * XXX CHECK XXX
 | 
					 | 
				
			||||||
         * When "poll_socket" is "1" libssh2_packet_ask_ex() could
 | 
					 | 
				
			||||||
         * return PACKET_EAGAIN.  Not sure the correct action, I
 | 
					 | 
				
			||||||
         * think it is right as is.
 | 
					 | 
				
			||||||
         */
 | 
					 | 
				
			||||||
        if (0 == _libssh2_packet_ask(session, packet_types[i], data,
 | 
					        if (0 == _libssh2_packet_ask(session, packet_types[i], data,
 | 
				
			||||||
                                    data_len, match_ofs, match_buf,
 | 
					                                     data_len, match_ofs,
 | 
				
			||||||
                                    match_len, i ? 0 : poll_socket)) {
 | 
					                                     match_buf, match_len)) {
 | 
				
			||||||
            return 0;
 | 
					            return 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -1096,7 +1078,7 @@ _libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type,
 | 
				
			|||||||
    if (state->start == 0) {
 | 
					    if (state->start == 0) {
 | 
				
			||||||
        if (_libssh2_packet_ask(session, packet_type, data, data_len,
 | 
					        if (_libssh2_packet_ask(session, packet_type, data, data_len,
 | 
				
			||||||
                               match_ofs, match_buf,
 | 
					                               match_ofs, match_buf,
 | 
				
			||||||
                               match_len, 0) == 0) {
 | 
					                               match_len) == 0) {
 | 
				
			||||||
            /* A packet was available in the packet brigade */
 | 
					            /* A packet was available in the packet brigade */
 | 
				
			||||||
            return 0;
 | 
					            return 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -1122,7 +1104,7 @@ _libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type,
 | 
				
			|||||||
        } else if (ret == packet_type) {
 | 
					        } else if (ret == packet_type) {
 | 
				
			||||||
            /* Be lazy, let packet_ask pull it out of the brigade */
 | 
					            /* Be lazy, let packet_ask pull it out of the brigade */
 | 
				
			||||||
            ret = _libssh2_packet_ask(session, packet_type, data, data_len,
 | 
					            ret = _libssh2_packet_ask(session, packet_type, data, data_len,
 | 
				
			||||||
                                     match_ofs, match_buf, match_len, 0);
 | 
					                                     match_ofs, match_buf, match_len);
 | 
				
			||||||
            state->start = 0;
 | 
					            state->start = 0;
 | 
				
			||||||
            return ret;
 | 
					            return ret;
 | 
				
			||||||
        } else if (ret == 0) {
 | 
					        } else if (ret == 0) {
 | 
				
			||||||
@@ -1141,10 +1123,10 @@ _libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type,
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * libssh2_packet_burn
 | 
					 * _libssh2_packet_burn
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Loops _libssh2_packet_read() until any packet is available and promptly
 | 
					 * Loops _libssh2_packet_read() until any packet is available and promptly
 | 
				
			||||||
 * discards it
 | 
					 * discards it.
 | 
				
			||||||
 * Used during KEX exchange to discard badly guessed KEX_INIT packets
 | 
					 * Used during KEX exchange to discard badly guessed KEX_INIT packets
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
@@ -1163,7 +1145,7 @@ _libssh2_packet_burn(LIBSSH2_SESSION * session,
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (_libssh2_packet_askv(session, all_packets, &data, &data_len, 0,
 | 
					        if (_libssh2_packet_askv(session, all_packets, &data, &data_len, 0,
 | 
				
			||||||
                                NULL, 0, 0) == 0) {
 | 
					                                 NULL, 0) == 0) {
 | 
				
			||||||
            i = data[0];
 | 
					            i = data[0];
 | 
				
			||||||
            /* A packet was available in the packet brigade, burn it */
 | 
					            /* A packet was available in the packet brigade, burn it */
 | 
				
			||||||
            LIBSSH2_FREE(session, data);
 | 
					            LIBSSH2_FREE(session, data);
 | 
				
			||||||
@@ -1188,7 +1170,7 @@ _libssh2_packet_burn(LIBSSH2_SESSION * session,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        /* Be lazy, let packet_ask pull it out of the brigade */
 | 
					        /* Be lazy, let packet_ask pull it out of the brigade */
 | 
				
			||||||
        if (0 ==
 | 
					        if (0 ==
 | 
				
			||||||
            _libssh2_packet_ask(session, ret, &data, &data_len, 0, NULL, 0, 0)) {
 | 
					            _libssh2_packet_ask(session, ret, &data, &data_len, 0, NULL, 0)) {
 | 
				
			||||||
            /* Smoke 'em if you got 'em */
 | 
					            /* Smoke 'em if you got 'em */
 | 
				
			||||||
            LIBSSH2_FREE(session, data);
 | 
					            LIBSSH2_FREE(session, data);
 | 
				
			||||||
            *state = libssh2_NB_state_idle;
 | 
					            *state = libssh2_NB_state_idle;
 | 
				
			||||||
@@ -1219,9 +1201,8 @@ _libssh2_packet_requirev(LIBSSH2_SESSION * session,
 | 
				
			|||||||
                         packet_requirev_state_t * state)
 | 
					                         packet_requirev_state_t * state)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (_libssh2_packet_askv(session, packet_types, data, data_len, match_ofs,
 | 
					    if (_libssh2_packet_askv(session, packet_types, data, data_len, match_ofs,
 | 
				
			||||||
                            match_buf, match_len, 0) == 0) {
 | 
					                             match_buf, match_len) == 0) {
 | 
				
			||||||
        /* One of the packets listed was available in the packet
 | 
					        /* One of the packets listed was available in the packet brigade */
 | 
				
			||||||
           brigade */
 | 
					 | 
				
			||||||
        state->start = 0;
 | 
					        state->start = 0;
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -1251,7 +1232,7 @@ _libssh2_packet_requirev(LIBSSH2_SESSION * session,
 | 
				
			|||||||
            /* Be lazy, let packet_ask pull it out of the brigade */
 | 
					            /* Be lazy, let packet_ask pull it out of the brigade */
 | 
				
			||||||
            return _libssh2_packet_askv(session, packet_types, data,
 | 
					            return _libssh2_packet_askv(session, packet_types, data,
 | 
				
			||||||
                                        data_len, match_ofs, match_buf,
 | 
					                                        data_len, match_ofs, match_buf,
 | 
				
			||||||
                                       match_len, 0);
 | 
					                                        match_len);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user