diff options
author | Xiang Xiao <xiaoxiang@xiaomi.com> | 2021-05-10 02:00:24 +0800 |
---|---|---|
committer | Jakub Jelen <jjelen@redhat.com> | 2021-06-16 11:56:44 +0200 |
commit | dbe504ea0ab0e803643fa44f35b6e4c259524c83 (patch) | |
tree | da1da2eba9543606f2dffb64247126e03b2d19db | |
parent | 14276f0b516f0bec63d8a737dba97334c68e528c (diff) | |
download | libssh-dbe504ea0ab0e803643fa44f35b6e4c259524c83.tar.gz libssh-dbe504ea0ab0e803643fa44f35b6e4c259524c83.tar.xz libssh-dbe504ea0ab0e803643fa44f35b6e4c259524c83.zip |
Make the transfer buffer size configurable
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Change-Id: I5052bac703b5a0c289ca5c28569cadeb54d3d507
-rw-r--r-- | examples/libssh_scp.c | 6 | ||||
-rw-r--r-- | examples/proxy.c | 8 | ||||
-rw-r--r-- | examples/samplesftp.c | 12 | ||||
-rw-r--r-- | examples/samplesshd-cb.c | 6 | ||||
-rw-r--r-- | examples/samplesshd-kbdint.c | 8 | ||||
-rw-r--r-- | examples/scp_download.c | 6 | ||||
-rw-r--r-- | examples/ssh_server.c | 5 | ||||
-rw-r--r-- | examples/sshd_direct-tcpip.c | 6 | ||||
-rw-r--r-- | examples/sshnetcat.c | 7 | ||||
-rw-r--r-- | src/connector.c | 2 | ||||
-rw-r--r-- | src/gzip.c | 2 |
11 files changed, 53 insertions, 15 deletions
diff --git a/examples/libssh_scp.c b/examples/libssh_scp.c index 0508d494..b81059b4 100644 --- a/examples/libssh_scp.c +++ b/examples/libssh_scp.c @@ -22,6 +22,10 @@ program. #include <libssh/libssh.h> #include "examples_common.h" +#ifndef BUF_SIZE +#define BUF_SIZE 16384 +#endif + static char **sources; static int nsources; static char *destination; @@ -257,7 +261,7 @@ static int do_copy(struct location *src, struct location *dest, int recursive) { socket_t fd; struct stat s; int w, r; - char buffer[16384]; + char buffer[BUF_SIZE]; size_t total = 0; mode_t mode; char *filename = NULL; diff --git a/examples/proxy.c b/examples/proxy.c index dcf4d0d7..159a37e5 100644 --- a/examples/proxy.c +++ b/examples/proxy.c @@ -25,6 +25,10 @@ clients must be made or how a client should react. #include <string.h> #include <stdio.h> +#ifndef BUF_SIZE +#define BUF_SIZE 2048 +#endif + #define USER "myuser" #define PASSWORD "mypassword" @@ -225,7 +229,7 @@ int main(int argc, char **argv){ .channel_open_request_session_function = new_session_channel }; - char buf[2048]; + char buf[BUF_SIZE]; char host[128]=""; char *ptr; int i,r, rc; @@ -291,7 +295,7 @@ int main(int argc, char **argv){ snprintf(buf,sizeof(buf), "Hello %s, welcome to the Sample SSH proxy.\r\nPlease select your destination: ", username); ssh_channel_write(chan, buf, strlen(buf)); do{ - i=ssh_channel_read(chan,buf, 2048, 0); + i=ssh_channel_read(chan,buf, sizeof(buf), 0); if(i>0) { ssh_channel_write(chan, buf, i); if(strlen(host) + i < sizeof(host)){ diff --git a/examples/samplesftp.c b/examples/samplesftp.c index a8624414..9c8cd34a 100644 --- a/examples/samplesftp.c +++ b/examples/samplesftp.c @@ -29,11 +29,13 @@ clients must be made or how a client should react. #include "examples_common.h" #ifdef WITH_SFTP +#ifndef BUF_SIZE +#define BUF_SIZE 65536 +#endif + static int verbosity; static char *destination; -#define DATALEN 65536 - static void do_sftp(ssh_session session) { sftp_session sftp = sftp_new(session); sftp_dir dir; @@ -44,7 +46,7 @@ static void do_sftp(ssh_session session) { sftp_file to; int len = 1; unsigned int i; - char data[DATALEN] = {0}; + char data[BUF_SIZE] = {0}; char *lnk; unsigned int count; @@ -223,9 +225,9 @@ static void do_sftp(ssh_session session) { to = sftp_open(sftp, "/tmp/grosfichier", O_WRONLY|O_CREAT, 0644); for (i = 0; i < 1000; ++i) { - len = sftp_write(to, data, DATALEN); + len = sftp_write(to, data, sizeof(data)); printf("wrote %d bytes\n", len); - if (len != DATALEN) { + if (len != sizeof(data)) { printf("chunk %d : %d (%s)\n", i, len, ssh_get_error(session)); } } diff --git a/examples/samplesshd-cb.c b/examples/samplesshd-cb.c index c0758a2e..628013aa 100644 --- a/examples/samplesshd-cb.c +++ b/examples/samplesshd-cb.c @@ -29,6 +29,10 @@ clients must be made or how a client should react. #include <io.h> #endif +#ifndef BUF_SIZE +#define BUF_SIZE 2049 +#endif + #ifndef KEYS_FOLDER #ifdef _WIN32 #define KEYS_FOLDER @@ -245,7 +249,7 @@ int main(int argc, char **argv){ .channel_open_request_session_function = new_session_channel }; - char buf[2049]; + char buf[BUF_SIZE]; int i; int r; diff --git a/examples/samplesshd-kbdint.c b/examples/samplesshd-kbdint.c index 522aebd6..9b09cf27 100644 --- a/examples/samplesshd-kbdint.c +++ b/examples/samplesshd-kbdint.c @@ -25,6 +25,10 @@ clients must be made or how a client should react. #include <stdio.h> #include <stdbool.h> +#ifndef BUF_SIZE +#define BUF_SIZE 2048 +#endif + #define SSHD_USER "libssh" #define SSHD_PASSWORD "libssh" @@ -293,7 +297,7 @@ int main(int argc, char **argv){ ssh_bind sshbind; ssh_message message; ssh_channel chan=0; - char buf[2048]; + char buf[BUF_SIZE]; int auth=0; int shell=0; int i; @@ -399,7 +403,7 @@ int main(int argc, char **argv){ printf("it works !\n"); do{ - i=ssh_channel_read(chan,buf, 2048, 0); + i=ssh_channel_read(chan,buf, sizeof(buf), 0); if(i>0) { if(*buf == '' || *buf == '') break; diff --git a/examples/scp_download.c b/examples/scp_download.c index 85ccf92b..e6c1e796 100644 --- a/examples/scp_download.c +++ b/examples/scp_download.c @@ -22,6 +22,10 @@ program. #include <libssh/libssh.h> #include "examples_common.h" +#ifndef BUF_SIZE +#define BUF_SIZE 16384 +#endif + static int verbosity = 0; static const char *createcommand = "rm -fr /tmp/libssh_tests && mkdir /tmp/libssh_tests && " @@ -102,7 +106,7 @@ static void create_files(ssh_session session){ static int fetch_files(ssh_session session){ int size; - char buffer[16384]; + char buffer[BUF_SIZE]; int mode; char *filename; int r; diff --git a/examples/ssh_server.c b/examples/ssh_server.c index 24c494e7..85eb1689 100644 --- a/examples/ssh_server.c +++ b/examples/ssh_server.c @@ -41,6 +41,10 @@ The goal is to show the API in action. #include <sys/stat.h> #include <stdio.h> +#ifndef BUF_SIZE +#define BUF_SIZE 1048576 +#endif + #ifndef KEYS_FOLDER #ifdef _WIN32 #define KEYS_FOLDER @@ -49,7 +53,6 @@ The goal is to show the API in action. #endif #endif -#define BUF_SIZE 1048576 #define SESSION_END (SSH_CLOSED | SSH_CLOSED_ERROR) #define SFTP_SERVER_PATH "/usr/lib/sftp-server" diff --git a/examples/sshd_direct-tcpip.c b/examples/sshd_direct-tcpip.c index 35898880..589c0889 100644 --- a/examples/sshd_direct-tcpip.c +++ b/examples/sshd_direct-tcpip.c @@ -35,6 +35,10 @@ clients must be made or how a client should react. #include <stdio.h> #include <poll.h> +#ifndef BUF_SIZE +#define BUF_SIZE 16384 +#endif + #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) #ifndef __unused__ @@ -349,7 +353,7 @@ my_fd_data_function(UNUSED_PARAM(socket_t fd), ssh_channel channel = event_fd_data->channel; ssh_session session; int len, i, wr; - char buf[16384]; + char buf[BUF_SIZE]; int blocking; if (channel == NULL) { diff --git a/examples/sshnetcat.c b/examples/sshnetcat.c index ccc72c86..9bc5d52e 100644 --- a/examples/sshnetcat.c +++ b/examples/sshnetcat.c @@ -34,6 +34,11 @@ clients must be made or how a client should react. #include <fcntl.h> #include "examples_common.h" + +#ifndef BUF_SIZE +#define BUF_SIZE 4096 +#endif + char *host; const char *desthost="localhost"; const char *port="22"; @@ -77,7 +82,7 @@ static int opts(int argc, char **argv){ static void select_loop(ssh_session session,ssh_channel channel){ fd_set fds; struct timeval timeout; - char buffer[4096]; + char buffer[BUF_SIZE]; /* channels will be set to the channels to poll. * outchannels will contain the result of the poll */ diff --git a/src/connector.c b/src/connector.c index ac841338..2ba0b665 100644 --- a/src/connector.c +++ b/src/connector.c @@ -30,7 +30,9 @@ #include <stdbool.h> #include <sys/stat.h> +#ifndef CHUNKSIZE #define CHUNKSIZE 4096 +#endif #ifdef _WIN32 # ifdef HAVE_IO_H @@ -33,7 +33,9 @@ #include "libssh/crypto.h" #include "libssh/session.h" +#ifndef BLOCKSIZE #define BLOCKSIZE 4092 +#endif static z_stream *initcompress(ssh_session session, int level) { z_stream *stream = NULL; |