Add LIBSSH2_TRACE_SOCKET context for tracing send() and recv()
Helpful in debugging the -39 errors.
Этот коммит содержится в:
родитель
1256c61815
Коммит
1a491c6f00
@ -883,6 +883,7 @@ LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask);
|
||||
#define LIBSSH2_TRACE_SFTP (1<<6)
|
||||
#define LIBSSH2_TRACE_ERROR (1<<7)
|
||||
#define LIBSSH2_TRACE_PUBLICKEY (1<<8)
|
||||
#define LIBSSH2_TRACE_SOCKET (1<<9)
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
@ -1022,6 +1022,8 @@ struct _LIBSSH2_MAC_METHOD
|
||||
#define LIBSSH2_DBG_SFTP 6
|
||||
#define LIBSSH2_DBG_ERROR 7
|
||||
#define LIBSSH2_DBG_PUBLICKEY 8
|
||||
#define LIBSSH2_DBG_SOCKET 9
|
||||
|
||||
#ifdef LIBSSH2DEBUG
|
||||
void _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format,
|
||||
...);
|
||||
@ -1271,4 +1273,7 @@ int _libssh2_pem_decode_integer(unsigned char **data, unsigned int *datalen,
|
||||
} while(1)
|
||||
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof ((a)) / sizeof ((a)[0]))
|
||||
|
||||
|
||||
#endif /* LIBSSH2_H */
|
||||
|
@ -320,7 +320,7 @@ _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
|
||||
va_list vargs;
|
||||
struct timeval now;
|
||||
static int firstsec;
|
||||
static const char *const contexts[9] = {
|
||||
static const char *const contexts[] = {
|
||||
"Unknown",
|
||||
"Transport",
|
||||
"Key Ex",
|
||||
@ -330,9 +330,10 @@ _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
|
||||
"SFTP",
|
||||
"Failure Event",
|
||||
"Publickey",
|
||||
"Socket",
|
||||
};
|
||||
|
||||
if (context < 1 || context > 8) {
|
||||
if (context < 1 || context >= (int)ARRAY_SIZE(contexts)) {
|
||||
context = 0;
|
||||
}
|
||||
if (!(session->showmask & (1 << context))) {
|
||||
|
@ -111,6 +111,12 @@ banner_receive(LIBSSH2_SESSION * session)
|
||||
|
||||
ret = _libssh2_recv(session->socket_fd, &c, 1,
|
||||
LIBSSH2_SOCKET_RECV_FLAGS(session));
|
||||
if (ret < 0)
|
||||
_libssh2_debug(session, LIBSSH2_DBG_SOCKET,
|
||||
"Error recving %d bytes to %p: %d", 1, &c, errno);
|
||||
else
|
||||
_libssh2_debug(session, LIBSSH2_DBG_SOCKET,
|
||||
"Recved %d bytes to %p", ret, &c);
|
||||
|
||||
if (ret < 0) {
|
||||
if (errno == EAGAIN) {
|
||||
@ -217,6 +223,15 @@ banner_send(LIBSSH2_SESSION * session)
|
||||
banner + session->banner_TxRx_total_send,
|
||||
banner_len - session->banner_TxRx_total_send,
|
||||
LIBSSH2_SOCKET_SEND_FLAGS(session));
|
||||
if (ret < 0)
|
||||
_libssh2_debug(session, LIBSSH2_DBG_SOCKET,
|
||||
"Error sending %d bytes: %d",
|
||||
banner_len - session->banner_TxRx_total_send, errno);
|
||||
else
|
||||
_libssh2_debug(session, LIBSSH2_DBG_SOCKET,
|
||||
"Sent %d/%d bytes at %p+%d", ret,
|
||||
banner_len - session->banner_TxRx_total_send,
|
||||
banner, session->banner_TxRx_total_send);
|
||||
|
||||
if (ret != (banner_len - session->banner_TxRx_total_send)) {
|
||||
if ((ret > 0) || ((ret == -1) && (errno == EAGAIN))) {
|
||||
|
@ -355,6 +355,15 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session)
|
||||
_libssh2_recv(session->socket_fd, &p->buf[remainbuf],
|
||||
PACKETBUFSIZE - remainbuf,
|
||||
LIBSSH2_SOCKET_RECV_FLAGS(session));
|
||||
if (nread < 0)
|
||||
_libssh2_debug(session, LIBSSH2_DBG_SOCKET,
|
||||
"Error recving %d bytes to %p+%d: %d",
|
||||
PACKETBUFSIZE - remainbuf, p->buf, remainbuf,
|
||||
errno);
|
||||
else
|
||||
_libssh2_debug(session, LIBSSH2_DBG_SOCKET,
|
||||
"Recved %d/%d bytes to %p+%d", nread,
|
||||
PACKETBUFSIZE - remainbuf, p->buf, remainbuf);
|
||||
if (nread <= 0) {
|
||||
/* check if this is due to EAGAIN and return the special
|
||||
return code if so, error out normally otherwise */
|
||||
@ -602,6 +611,13 @@ send_existing(LIBSSH2_SESSION * session, unsigned char *data,
|
||||
|
||||
rc = _libssh2_send(session->socket_fd, &p->outbuf[p->osent], length,
|
||||
LIBSSH2_SOCKET_SEND_FLAGS(session));
|
||||
if (rc < 0)
|
||||
_libssh2_debug(session, LIBSSH2_DBG_SOCKET,
|
||||
"Error sending %d bytes: %d", length, errno);
|
||||
else
|
||||
_libssh2_debug(session, LIBSSH2_DBG_SOCKET,
|
||||
"Sent %d/%d bytes at %p+%d", rc, length, p->outbuf,
|
||||
p->osent);
|
||||
|
||||
if(rc > 0) {
|
||||
debugdump(session, "libssh2_transport_write send()",
|
||||
@ -776,6 +792,12 @@ _libssh2_transport_write(LIBSSH2_SESSION * session, unsigned char *data,
|
||||
|
||||
ret = _libssh2_send(session->socket_fd, p->outbuf, total_length,
|
||||
LIBSSH2_SOCKET_SEND_FLAGS(session));
|
||||
if (ret < 0)
|
||||
_libssh2_debug(session, LIBSSH2_DBG_SOCKET,
|
||||
"Error sending %d bytes: %d", total_length, errno);
|
||||
else
|
||||
_libssh2_debug(session, LIBSSH2_DBG_SOCKET, "Sent %d/%d bytes at %p",
|
||||
ret, total_length, p->outbuf);
|
||||
|
||||
if (ret != -1) {
|
||||
debugdump(session, "libssh2_transport_write send()", p->outbuf, ret);
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user