2008/11/27 Daniel Stenberg <[EMAIL PROTECTED]>:
>> Does anyone have any ideas what might be happening? I'm afraid I haven't
>> got a clue where to start debugging this.
Firstly, apologies for my stupidity. The part of my previous email
about the speed-up was because I forgot to call
libssh2_sftp_seek(handle, 0) inside the loop so eventually it ran off
the end of the file. However the overall question of why there is a
threshold for the buffer size of 39992, still applies.
> Can you provide us with the source for a full app that reproduces the problem?
>
> Preferably as small as possible, and without too much windows-specific code...
I have attached the code you ask. Most of the window-specific stuff
is gone but I may have missed something. Also, I'm not sure what
should be included in the place of Winsock for unix. Maybe nothing.
Many thanks.
Alex
#ifdef WIN32
#define LIBSSH2_WIN32
#include <ws2tcpip.h> // Winsock
#include <wspiapi.h> // Winsock
#endif
#include <libssh2.h>
#include <libssh2_sftp.h>
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;
#include <assert.h>
SOCKET _OpenSocketToHost(const char *host, unsigned int port)
{
// The hints address info struct which is passed to getaddrinfo()
addrinfo aiHints;
memset(&aiHints, 0, sizeof(aiHints));
aiHints.ai_family = AF_INET;
aiHints.ai_socktype = SOCK_STREAM;
aiHints.ai_protocol = IPPROTO_TCP;
// Convert numeric port to a UTF-8 string
char szPort[6];
_itoa_s(port, szPort, 6, 10);
// Call getaddrinfo(). If the call succeeds, paiList will hold a linked
list
// of addrinfo structures containing response information about the
host.
addrinfo *paiList = NULL;
int rc = getaddrinfo(host, szPort, &aiHints, &paiList);
if (rc != 0)
{
cerr << "host lookup failed: " << host << ":" << port << endl;
exit(1);
}
// Create socket and establish connection
SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock != INVALID_SOCKET)
{
connect(sock, paiList->ai_addr,
static_cast<int>(paiList->ai_addrlen));
}
freeaddrinfo(paiList);
return sock;
}
int main(int argc, char* argv[])
{
#ifdef WIN32
// Start up Winsock
WSADATA wsadata;
int rc = ::WSAStartup(WINSOCK_VERSION, &wsadata);
#endif
// Connect to host over TCP/IP
SOCKET sock = _OpenSocketToHost("defiant.lammy.co.uk", 22);
// Start up libssh2 and trade welcome banners, exchange keys,
// setup crypto, compression, and MAC layers
LIBSSH2_SESSION *session = libssh2_session_init();
if (libssh2_session_startup(session, static_cast<int>(sock)) != 0)
{
cerr << "libssh2_session_startup() failed" << endl;
exit(1);
}
// Tell libssh2 we are blocking
libssh2_session_set_blocking(session, 1);
// Login
int ret = libssh2_userauth_password(session, "swish", "/.,mnbvc");
if (ret != 0)
{
cerr << "login failed" << endl;
exit(1);
}
// SFTP
LIBSSH2_SFTP *sftp = libssh2_sftp_init(session);
// Open file
LIBSSH2_SFTP_HANDLE *handle = libssh2_sftp_open(sftp,
"/home/swish/Examples/oo-presenting-kubuntu.odp",
LIBSSH2_FXF_READ, NULL);
if (handle == NULL)
{
cerr << "opening file failed" << endl;
exit(1);
}
// Read file
for (unsigned long i = 39900; i < 6000000; i+=1)
{
cout << "trying buffer size " << i << endl;
char *buf = new char[i];
libssh2_sftp_seek(handle, 0);
ssize_t cbRead = libssh2_sftp_read(handle, buf, i);
delete [] buf;
if (cbRead < 0)
{
cerr << "libssh2_sftp_read() failed" << endl;
exit(1);
}
}
return 0;
}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
libssh2-devel mailing list
libssh2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel