Make the transfer buffer size configurable
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Change-Id: I5052bac703b5a0c289ca5c28569cadeb54d3d507
This commit is contained in:
parent
14276f0b51
commit
dbe504ea0a
@ -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;
|
||||
|
@ -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)){
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user