Make the transfer buffer size configurable
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Change-Id: I5052bac703b5a0c289ca5c28569cadeb54d3d507
Этот коммит содержится в:
родитель
14276f0b51
Коммит
dbe504ea0a
@ -22,6 +22,10 @@ program.
|
|||||||
#include <libssh/libssh.h>
|
#include <libssh/libssh.h>
|
||||||
#include "examples_common.h"
|
#include "examples_common.h"
|
||||||
|
|
||||||
|
#ifndef BUF_SIZE
|
||||||
|
#define BUF_SIZE 16384
|
||||||
|
#endif
|
||||||
|
|
||||||
static char **sources;
|
static char **sources;
|
||||||
static int nsources;
|
static int nsources;
|
||||||
static char *destination;
|
static char *destination;
|
||||||
@ -257,7 +261,7 @@ static int do_copy(struct location *src, struct location *dest, int recursive) {
|
|||||||
socket_t fd;
|
socket_t fd;
|
||||||
struct stat s;
|
struct stat s;
|
||||||
int w, r;
|
int w, r;
|
||||||
char buffer[16384];
|
char buffer[BUF_SIZE];
|
||||||
size_t total = 0;
|
size_t total = 0;
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
|
@ -25,6 +25,10 @@ clients must be made or how a client should react.
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifndef BUF_SIZE
|
||||||
|
#define BUF_SIZE 2048
|
||||||
|
#endif
|
||||||
|
|
||||||
#define USER "myuser"
|
#define USER "myuser"
|
||||||
#define PASSWORD "mypassword"
|
#define PASSWORD "mypassword"
|
||||||
|
|
||||||
@ -225,7 +229,7 @@ int main(int argc, char **argv){
|
|||||||
.channel_open_request_session_function = new_session_channel
|
.channel_open_request_session_function = new_session_channel
|
||||||
};
|
};
|
||||||
|
|
||||||
char buf[2048];
|
char buf[BUF_SIZE];
|
||||||
char host[128]="";
|
char host[128]="";
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int i,r, rc;
|
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);
|
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));
|
ssh_channel_write(chan, buf, strlen(buf));
|
||||||
do{
|
do{
|
||||||
i=ssh_channel_read(chan,buf, 2048, 0);
|
i=ssh_channel_read(chan,buf, sizeof(buf), 0);
|
||||||
if(i>0) {
|
if(i>0) {
|
||||||
ssh_channel_write(chan, buf, i);
|
ssh_channel_write(chan, buf, i);
|
||||||
if(strlen(host) + i < sizeof(host)){
|
if(strlen(host) + i < sizeof(host)){
|
||||||
|
@ -29,11 +29,13 @@ clients must be made or how a client should react.
|
|||||||
#include "examples_common.h"
|
#include "examples_common.h"
|
||||||
#ifdef WITH_SFTP
|
#ifdef WITH_SFTP
|
||||||
|
|
||||||
|
#ifndef BUF_SIZE
|
||||||
|
#define BUF_SIZE 65536
|
||||||
|
#endif
|
||||||
|
|
||||||
static int verbosity;
|
static int verbosity;
|
||||||
static char *destination;
|
static char *destination;
|
||||||
|
|
||||||
#define DATALEN 65536
|
|
||||||
|
|
||||||
static void do_sftp(ssh_session session) {
|
static void do_sftp(ssh_session session) {
|
||||||
sftp_session sftp = sftp_new(session);
|
sftp_session sftp = sftp_new(session);
|
||||||
sftp_dir dir;
|
sftp_dir dir;
|
||||||
@ -44,7 +46,7 @@ static void do_sftp(ssh_session session) {
|
|||||||
sftp_file to;
|
sftp_file to;
|
||||||
int len = 1;
|
int len = 1;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
char data[DATALEN] = {0};
|
char data[BUF_SIZE] = {0};
|
||||||
char *lnk;
|
char *lnk;
|
||||||
|
|
||||||
unsigned int count;
|
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);
|
to = sftp_open(sftp, "/tmp/grosfichier", O_WRONLY|O_CREAT, 0644);
|
||||||
|
|
||||||
for (i = 0; i < 1000; ++i) {
|
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);
|
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));
|
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>
|
#include <io.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef BUF_SIZE
|
||||||
|
#define BUF_SIZE 2049
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef KEYS_FOLDER
|
#ifndef KEYS_FOLDER
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define KEYS_FOLDER
|
#define KEYS_FOLDER
|
||||||
@ -245,7 +249,7 @@ int main(int argc, char **argv){
|
|||||||
.channel_open_request_session_function = new_session_channel
|
.channel_open_request_session_function = new_session_channel
|
||||||
};
|
};
|
||||||
|
|
||||||
char buf[2049];
|
char buf[BUF_SIZE];
|
||||||
int i;
|
int i;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -25,6 +25,10 @@ clients must be made or how a client should react.
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifndef BUF_SIZE
|
||||||
|
#define BUF_SIZE 2048
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SSHD_USER "libssh"
|
#define SSHD_USER "libssh"
|
||||||
#define SSHD_PASSWORD "libssh"
|
#define SSHD_PASSWORD "libssh"
|
||||||
|
|
||||||
@ -293,7 +297,7 @@ int main(int argc, char **argv){
|
|||||||
ssh_bind sshbind;
|
ssh_bind sshbind;
|
||||||
ssh_message message;
|
ssh_message message;
|
||||||
ssh_channel chan=0;
|
ssh_channel chan=0;
|
||||||
char buf[2048];
|
char buf[BUF_SIZE];
|
||||||
int auth=0;
|
int auth=0;
|
||||||
int shell=0;
|
int shell=0;
|
||||||
int i;
|
int i;
|
||||||
@ -399,7 +403,7 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
printf("it works !\n");
|
printf("it works !\n");
|
||||||
do{
|
do{
|
||||||
i=ssh_channel_read(chan,buf, 2048, 0);
|
i=ssh_channel_read(chan,buf, sizeof(buf), 0);
|
||||||
if(i>0) {
|
if(i>0) {
|
||||||
if(*buf == '' || *buf == '')
|
if(*buf == '' || *buf == '')
|
||||||
break;
|
break;
|
||||||
|
@ -22,6 +22,10 @@ program.
|
|||||||
#include <libssh/libssh.h>
|
#include <libssh/libssh.h>
|
||||||
#include "examples_common.h"
|
#include "examples_common.h"
|
||||||
|
|
||||||
|
#ifndef BUF_SIZE
|
||||||
|
#define BUF_SIZE 16384
|
||||||
|
#endif
|
||||||
|
|
||||||
static int verbosity = 0;
|
static int verbosity = 0;
|
||||||
static const char *createcommand =
|
static const char *createcommand =
|
||||||
"rm -fr /tmp/libssh_tests && mkdir /tmp/libssh_tests && "
|
"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){
|
static int fetch_files(ssh_session session){
|
||||||
int size;
|
int size;
|
||||||
char buffer[16384];
|
char buffer[BUF_SIZE];
|
||||||
int mode;
|
int mode;
|
||||||
char *filename;
|
char *filename;
|
||||||
int r;
|
int r;
|
||||||
|
@ -41,6 +41,10 @@ The goal is to show the API in action.
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifndef BUF_SIZE
|
||||||
|
#define BUF_SIZE 1048576
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef KEYS_FOLDER
|
#ifndef KEYS_FOLDER
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define KEYS_FOLDER
|
#define KEYS_FOLDER
|
||||||
@ -49,7 +53,6 @@ The goal is to show the API in action.
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BUF_SIZE 1048576
|
|
||||||
#define SESSION_END (SSH_CLOSED | SSH_CLOSED_ERROR)
|
#define SESSION_END (SSH_CLOSED | SSH_CLOSED_ERROR)
|
||||||
#define SFTP_SERVER_PATH "/usr/lib/sftp-server"
|
#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 <stdio.h>
|
||||||
#include <poll.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)
|
#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
|
||||||
|
|
||||||
#ifndef __unused__
|
#ifndef __unused__
|
||||||
@ -349,7 +353,7 @@ my_fd_data_function(UNUSED_PARAM(socket_t fd),
|
|||||||
ssh_channel channel = event_fd_data->channel;
|
ssh_channel channel = event_fd_data->channel;
|
||||||
ssh_session session;
|
ssh_session session;
|
||||||
int len, i, wr;
|
int len, i, wr;
|
||||||
char buf[16384];
|
char buf[BUF_SIZE];
|
||||||
int blocking;
|
int blocking;
|
||||||
|
|
||||||
if (channel == NULL) {
|
if (channel == NULL) {
|
||||||
|
@ -34,6 +34,11 @@ clients must be made or how a client should react.
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "examples_common.h"
|
#include "examples_common.h"
|
||||||
|
|
||||||
|
#ifndef BUF_SIZE
|
||||||
|
#define BUF_SIZE 4096
|
||||||
|
#endif
|
||||||
|
|
||||||
char *host;
|
char *host;
|
||||||
const char *desthost="localhost";
|
const char *desthost="localhost";
|
||||||
const char *port="22";
|
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){
|
static void select_loop(ssh_session session,ssh_channel channel){
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
char buffer[4096];
|
char buffer[BUF_SIZE];
|
||||||
/* channels will be set to the channels to poll.
|
/* channels will be set to the channels to poll.
|
||||||
* outchannels will contain the result of the poll
|
* outchannels will contain the result of the poll
|
||||||
*/
|
*/
|
||||||
|
@ -30,7 +30,9 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#ifndef CHUNKSIZE
|
||||||
#define CHUNKSIZE 4096
|
#define CHUNKSIZE 4096
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# ifdef HAVE_IO_H
|
# ifdef HAVE_IO_H
|
||||||
|
@ -33,7 +33,9 @@
|
|||||||
#include "libssh/crypto.h"
|
#include "libssh/crypto.h"
|
||||||
#include "libssh/session.h"
|
#include "libssh/session.h"
|
||||||
|
|
||||||
|
#ifndef BLOCKSIZE
|
||||||
#define BLOCKSIZE 4092
|
#define BLOCKSIZE 4092
|
||||||
|
#endif
|
||||||
|
|
||||||
static z_stream *initcompress(ssh_session session, int level) {
|
static z_stream *initcompress(ssh_session session, int level) {
|
||||||
z_stream *stream = NULL;
|
z_stream *stream = NULL;
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user