made sure the SFTP code makes more use of internal non-blocking functions
instead of the external API entries
This commit is contained in:
parent
60ee30b6c9
commit
117b95e6e3
@ -116,12 +116,12 @@ _libssh2_channel_locate(LIBSSH2_SESSION * session, unsigned long channel_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* channel_open
|
* _libssh2_channel_open
|
||||||
*
|
*
|
||||||
* Establish a generic session channel
|
* Establish a generic session channel
|
||||||
*/
|
*/
|
||||||
static LIBSSH2_CHANNEL *
|
LIBSSH2_CHANNEL *
|
||||||
channel_open(LIBSSH2_SESSION * session, const char *channel_type,
|
_libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
|
||||||
unsigned int channel_type_len,
|
unsigned int channel_type_len,
|
||||||
unsigned int window_size, unsigned int packet_size,
|
unsigned int window_size, unsigned int packet_size,
|
||||||
const char *message, unsigned int message_len)
|
const char *message, unsigned int message_len)
|
||||||
@ -342,7 +342,8 @@ libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *type,
|
|||||||
const char *msg, unsigned int msg_len)
|
const char *msg, unsigned int msg_len)
|
||||||
{
|
{
|
||||||
LIBSSH2_CHANNEL *ptr;
|
LIBSSH2_CHANNEL *ptr;
|
||||||
BLOCK_ADJUST_ERRNO(ptr, session, channel_open(session, type, type_len,
|
BLOCK_ADJUST_ERRNO(ptr, session,
|
||||||
|
_libssh2_channel_open(session, type, type_len,
|
||||||
window_size, packet_size,
|
window_size, packet_size,
|
||||||
msg, msg_len));
|
msg, msg_len));
|
||||||
return ptr;
|
return ptr;
|
||||||
@ -1304,12 +1305,12 @@ libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel, int single_connection,
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* libssh2_channel_process_startup
|
* _libssh2_channel_process_startup
|
||||||
*
|
*
|
||||||
* Primitive for libssh2_channel_(shell|exec|subsystem)
|
* Primitive for libssh2_channel_(shell|exec|subsystem)
|
||||||
*/
|
*/
|
||||||
static int
|
int
|
||||||
channel_process_startup(LIBSSH2_CHANNEL *channel,
|
_libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
|
||||||
const char *request, unsigned int request_len,
|
const char *request, unsigned int request_len,
|
||||||
const char *message, unsigned int message_len)
|
const char *message, unsigned int message_len)
|
||||||
{
|
{
|
||||||
@ -1424,7 +1425,8 @@ libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
|
|||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
BLOCK_ADJUST(rc, channel->session,
|
BLOCK_ADJUST(rc, channel->session,
|
||||||
channel_process_startup(channel, req, req_len, msg, msg_len));
|
_libssh2_channel_process_startup(channel, req, req_len,
|
||||||
|
msg, msg_len));
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1985,12 +1987,12 @@ _libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel, int stream_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* channel_write
|
* _libssh2_channel_write
|
||||||
*
|
*
|
||||||
* Send data to a channel
|
* Send data to a channel
|
||||||
*/
|
*/
|
||||||
static ssize_t
|
ssize_t
|
||||||
channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
|
_libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
|
||||||
const char *buf, size_t buflen)
|
const char *buf, size_t buflen)
|
||||||
{
|
{
|
||||||
LIBSSH2_SESSION *session = channel->session;
|
LIBSSH2_SESSION *session = channel->session;
|
||||||
@ -2161,7 +2163,7 @@ libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel, int stream_id,
|
|||||||
{
|
{
|
||||||
ssize_t rc;
|
ssize_t rc;
|
||||||
BLOCK_ADJUST(rc, channel->session,
|
BLOCK_ADJUST(rc, channel->session,
|
||||||
channel_write(channel, stream_id, buf, buflen));
|
_libssh2_channel_write(channel, stream_id, buf, buflen));
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,5 +73,36 @@ int _libssh2_channel_free(LIBSSH2_CHANNEL *channel);
|
|||||||
int
|
int
|
||||||
_libssh2_channel_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode);
|
_libssh2_channel_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* _libssh2_channel_write
|
||||||
|
*
|
||||||
|
* Send data to a channel
|
||||||
|
*/
|
||||||
|
ssize_t
|
||||||
|
_libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
|
||||||
|
const char *buf, size_t buflen);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* _libssh2_channel_open
|
||||||
|
*
|
||||||
|
* Establish a generic session channel
|
||||||
|
*/
|
||||||
|
LIBSSH2_CHANNEL *
|
||||||
|
_libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
|
||||||
|
unsigned int channel_type_len,
|
||||||
|
unsigned int window_size, unsigned int packet_size,
|
||||||
|
const char *message, unsigned int message_len);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* _libssh2_channel_process_startup
|
||||||
|
*
|
||||||
|
* Primitive for libssh2_channel_(shell|exec|subsystem)
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
_libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
|
||||||
|
const char *request, unsigned int request_len,
|
||||||
|
const char *message, unsigned int message_len);
|
||||||
|
|
||||||
#endif /* __LIBSSH2_CHANNEL_H */
|
#endif /* __LIBSSH2_CHANNEL_H */
|
||||||
|
|
||||||
|
36
src/sftp.c
36
src/sftp.c
@ -572,7 +572,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
|
|||||||
|
|
||||||
if (session->sftpInit_state == libssh2_NB_state_created) {
|
if (session->sftpInit_state == libssh2_NB_state_created) {
|
||||||
session->sftpInit_channel =
|
session->sftpInit_channel =
|
||||||
libssh2_channel_open_ex(session, "session", sizeof("session") - 1,
|
_libssh2_channel_open(session, "session", sizeof("session") - 1,
|
||||||
LIBSSH2_CHANNEL_WINDOW_DEFAULT,
|
LIBSSH2_CHANNEL_WINDOW_DEFAULT,
|
||||||
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0);
|
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0);
|
||||||
if (!session->sftpInit_channel) {
|
if (!session->sftpInit_channel) {
|
||||||
@ -592,7 +592,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session->sftpInit_state == libssh2_NB_state_sent) {
|
if (session->sftpInit_state == libssh2_NB_state_sent) {
|
||||||
rc = libssh2_channel_process_startup(session->sftpInit_channel,
|
rc = _libssh2_channel_process_startup(session->sftpInit_channel,
|
||||||
"subsystem",
|
"subsystem",
|
||||||
sizeof("subsystem") - 1, "sftp",
|
sizeof("subsystem") - 1, "sftp",
|
||||||
strlen("sftp"));
|
strlen("sftp"));
|
||||||
@ -640,7 +640,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session->sftpInit_state == libssh2_NB_state_sent2) {
|
if (session->sftpInit_state == libssh2_NB_state_sent2) {
|
||||||
rc = libssh2_channel_write_ex(session->sftpInit_channel, 0,
|
rc = _libssh2_channel_write(session->sftpInit_channel, 0,
|
||||||
(char *) session->sftpInit_buffer, 9);
|
(char *) session->sftpInit_buffer, 9);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
@ -879,7 +879,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sftp->open_state == libssh2_NB_state_created) {
|
if (sftp->open_state == libssh2_NB_state_created) {
|
||||||
rc = libssh2_channel_write_ex(channel, 0, (char *) sftp->open_packet,
|
rc = _libssh2_channel_write(channel, 0, (char *) sftp->open_packet,
|
||||||
sftp->open_packet_len);
|
sftp->open_packet_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
@ -1094,8 +1094,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sftp->read_state == libssh2_NB_state_created) {
|
if (sftp->read_state == libssh2_NB_state_created) {
|
||||||
retcode =
|
retcode = _libssh2_channel_write(channel, 0, (char *) packet,
|
||||||
libssh2_channel_write_ex(channel, 0, (char *) packet,
|
|
||||||
packet_len);
|
packet_len);
|
||||||
if (retcode == PACKET_EAGAIN) {
|
if (retcode == PACKET_EAGAIN) {
|
||||||
sftp->read_packet = packet;
|
sftp->read_packet = packet;
|
||||||
@ -1298,11 +1297,9 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
|
|||||||
if (sftp->readdir_state == libssh2_NB_state_created) {
|
if (sftp->readdir_state == libssh2_NB_state_created) {
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_SFTP,
|
_libssh2_debug(session, LIBSSH2_DBG_SFTP,
|
||||||
"Reading entries from directory handle");
|
"Reading entries from directory handle");
|
||||||
retcode =
|
retcode = _libssh2_channel_write(channel, 0,
|
||||||
libssh2_channel_write_ex(channel, 0,
|
|
||||||
(char *) sftp->readdir_packet,
|
(char *) sftp->readdir_packet,
|
||||||
packet_len);
|
packet_len);
|
||||||
|
|
||||||
if (retcode == PACKET_EAGAIN) {
|
if (retcode == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
}
|
||||||
@ -1459,8 +1456,7 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE * handle, const char *buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sftp->write_state == libssh2_NB_state_created) {
|
if (sftp->write_state == libssh2_NB_state_created) {
|
||||||
rc =
|
rc = _libssh2_channel_write(channel, 0, (char *) sftp->write_packet,
|
||||||
libssh2_channel_write_ex(channel, 0, (char *) sftp->write_packet,
|
|
||||||
packet_len);
|
packet_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
@ -1568,7 +1564,7 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sftp->fstat_state == libssh2_NB_state_created) {
|
if (sftp->fstat_state == libssh2_NB_state_created) {
|
||||||
rc = libssh2_channel_write_ex(channel, 0, (char *) sftp->fstat_packet,
|
rc = _libssh2_channel_write(channel, 0, (char *) sftp->fstat_packet,
|
||||||
packet_len);
|
packet_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
@ -1711,8 +1707,7 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (handle->close_state == libssh2_NB_state_created) {
|
if (handle->close_state == libssh2_NB_state_created) {
|
||||||
rc = libssh2_channel_write_ex(channel, 0,
|
rc = _libssh2_channel_write(channel, 0, (char *) handle->close_packet,
|
||||||
(char *) handle->close_packet,
|
|
||||||
packet_len);
|
packet_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
@ -1828,7 +1823,7 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sftp->unlink_state == libssh2_NB_state_created) {
|
if (sftp->unlink_state == libssh2_NB_state_created) {
|
||||||
rc = libssh2_channel_write_ex(channel, 0, (char *) sftp->unlink_packet,
|
rc = _libssh2_channel_write(channel, 0, (char *) sftp->unlink_packet,
|
||||||
packet_len);
|
packet_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
@ -1950,7 +1945,7 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sftp->rename_state == libssh2_NB_state_created) {
|
if (sftp->rename_state == libssh2_NB_state_created) {
|
||||||
rc = libssh2_channel_write_ex(channel, 0, (char *) sftp->rename_packet,
|
rc = _libssh2_channel_write(channel, 0, (char *) sftp->rename_packet,
|
||||||
sftp->rename_s - sftp->rename_packet);
|
sftp->rename_s - sftp->rename_packet);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
@ -2081,7 +2076,7 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sftp->mkdir_state == libssh2_NB_state_created) {
|
if (sftp->mkdir_state == libssh2_NB_state_created) {
|
||||||
rc = libssh2_channel_write_ex(channel, 0, (char *) packet, packet_len);
|
rc = _libssh2_channel_write(channel, 0, (char *) packet, packet_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
sftp->mkdir_packet = packet;
|
sftp->mkdir_packet = packet;
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
@ -2179,7 +2174,7 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sftp->rmdir_state == libssh2_NB_state_created) {
|
if (sftp->rmdir_state == libssh2_NB_state_created) {
|
||||||
rc = libssh2_channel_write_ex(channel, 0, (char *) sftp->rmdir_packet,
|
rc = _libssh2_channel_write(channel, 0, (char *) sftp->rmdir_packet,
|
||||||
packet_len);
|
packet_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
@ -2298,7 +2293,7 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sftp->stat_state == libssh2_NB_state_created) {
|
if (sftp->stat_state == libssh2_NB_state_created) {
|
||||||
rc = libssh2_channel_write_ex(channel, 0, (char *) sftp->stat_packet,
|
rc = _libssh2_channel_write(channel, 0, (char *) sftp->stat_packet,
|
||||||
packet_len);
|
packet_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
@ -2438,8 +2433,7 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sftp->symlink_state == libssh2_NB_state_created) {
|
if (sftp->symlink_state == libssh2_NB_state_created) {
|
||||||
rc = libssh2_channel_write_ex(channel, 0,
|
rc = _libssh2_channel_write(channel, 0, (char *) sftp->symlink_packet,
|
||||||
(char *) sftp->symlink_packet,
|
|
||||||
packet_len);
|
packet_len);
|
||||||
if (rc == PACKET_EAGAIN) {
|
if (rc == PACKET_EAGAIN) {
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user