diff --git a/examples/echoserver/echoserver.c b/examples/echoserver/echoserver.c index 8ca32e7..3169800 100644 --- a/examples/echoserver/echoserver.c +++ b/examples/echoserver/echoserver.c @@ -325,6 +325,16 @@ static int sftp_worker(thread_ctx_t* threadCtx) { if (error == WS_WANT_READ || error == WS_WANT_WRITE) ret = WS_WANT_READ; + if (ret == WS_FATAL_ERROR && error == 0) { + WOLFSSH_CHANNEL* channel = + wolfSSH_ChannelNext(threadCtx->ssh, NULL); + if (channel && wolfSSH_ChannelGetEof(channel)) { + ret = 0; + error = 0; + break; + } + } + } while (ret != WS_FATAL_ERROR); return ret; @@ -372,7 +382,7 @@ wolfSSL_Mutex doneLock; static THREAD_RETURN WOLFSSH_THREAD server_worker(void* vArgs) { - int ret = 0; + int ret = 0, error = 0; thread_ctx_t* threadCtx = (thread_ctx_t*)vArgs; if (!threadCtx->nonBlock) @@ -399,19 +409,31 @@ static THREAD_RETURN WOLFSSH_THREAD server_worker(void* vArgs) break; } - if (ret == WS_FATAL_ERROR && wolfSSH_get_error(threadCtx->ssh) == - WS_VERSION_E) { - ret = 0; /* don't break out of loop with version miss match */ - printf("Unsupported version error\n"); - } - else if (ret == WS_FATAL_ERROR && wolfSSH_get_error(threadCtx->ssh) == - WS_USER_AUTH_E) { - ret = 0; /* don't break out of loop with user auth error */ - printf("User Authentication error\n"); + if (ret == WS_FATAL_ERROR) { + const char* errorStr; + error = wolfSSH_get_error(threadCtx->ssh); + + errorStr = wolfSSH_ErrorToName(error); + + if (error == WS_VERSION_E) { + ret = 0; /* don't break out of loop with version miss match */ + printf("%s\n", errorStr); + } + else if (error == WS_USER_AUTH_E) { + ret = 0; /* don't break out of loop with user auth error */ + printf("%s\n", errorStr); + } + else if (error == WS_SOCKET_ERROR_E) { + ret = 0; + printf("%s\n", errorStr); + } } - if (wolfSSH_shutdown(threadCtx->ssh) != WS_SUCCESS) { - fprintf(stderr, "Error with SSH shutdown.\n"); + if (error != WS_SOCKET_ERROR_E && error != WS_FATAL_ERROR) + { + if (wolfSSH_shutdown(threadCtx->ssh) != WS_SUCCESS) { + fprintf(stderr, "Error with SSH shutdown.\n"); + } } WCLOSESOCKET(threadCtx->fd); @@ -419,7 +441,7 @@ static THREAD_RETURN WOLFSSH_THREAD server_worker(void* vArgs) if (ret != 0) { fprintf(stderr, "Error [%d] \"%s\" with handling connection.\n", ret, - wolfSSH_ErrorToName(ret)); + wolfSSH_ErrorToName(error)); #ifndef WOLFSSH_NO_EXIT wc_LockMutex(&doneLock); quit = 1; diff --git a/src/ssh.c b/src/ssh.c index 66e5bf2..c1068fa 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -1574,6 +1574,21 @@ WOLFSSH_CHANNEL* wolfSSH_ChannelNext(WOLFSSH* ssh, WOLFSSH_CHANNEL* channel) } +int wolfSSH_ChannelGetEof(WOLFSSH_CHANNEL* channel) +{ + int eof = 1; + + WLOG(WS_LOG_DEBUG, "Entering wolfSSH_ChannelGetEof()"); + + if (channel) + eof = (int)channel->receivedEof; + + WLOG(WS_LOG_DEBUG, "Leaving wolfSSH_ChannelGetEof(), %s", + eof ? "true" : "false"); + return eof; +} + + /* Protocols that have loops over wolfSSH_stream_send without doing any reads * will run into the issue of not checking for a peer window adjustment packet. * This function allows for checking for a peer window adjustment packet without diff --git a/src/wolfsftp.c b/src/wolfsftp.c index 19c0166..c6dc60b 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -553,6 +553,7 @@ static int SFTP_GetHeader(WOLFSSH* ssh, word32* reqId, byte* type) int ret; word32 len; byte buf[WOLFSSH_SFTP_HEADER]; + WLOG(WS_LOG_SFTP, "Entering SFTP_GetHeader()"); if (type == NULL || reqId == NULL || ssh == NULL) { WLOG(WS_LOG_SFTP, "NULL argument error"); @@ -573,6 +574,8 @@ static int SFTP_GetHeader(WOLFSSH* ssh, word32* reqId, byte* type) *type = buf[LENGTH_SZ]; ato32(buf + UINT32_SZ + MSG_ID_SZ, reqId); + WLOG(WS_LOG_SFTP, "Leaving SFTP_GetHeader(), %d", + len - UINT32_SZ - MSG_ID_SZ); return len - UINT32_SZ - MSG_ID_SZ; } @@ -1007,6 +1010,8 @@ int wolfSSH_SFTP_read(WOLFSSH* ssh) int maxSz, ret = WS_SUCCESS; WS_SFTP_RECV_STATE* state = NULL; + WLOG(WS_LOG_DEBUG, "Entering wolfSSH_SFTP_read()"); + if (ssh == NULL) return WS_BAD_ARGUMENT; diff --git a/wolfssh/ssh.h b/wolfssh/ssh.h index 0a75cb0..0cd0668 100644 --- a/wolfssh/ssh.h +++ b/wolfssh/ssh.h @@ -92,6 +92,7 @@ WOLFSSH_API int wolfSSH_ChannelGetFwdFd(const WOLFSSH_CHANNEL*); WOLFSSH_API int wolfSSH_ChannelRead(WOLFSSH_CHANNEL*, byte*, word32); WOLFSSH_API int wolfSSH_ChannelSend(WOLFSSH_CHANNEL*, const byte*, word32); WOLFSSH_API int wolfSSH_ChannelExit(WOLFSSH_CHANNEL*); +WOLFSSH_API int wolfSSH_ChannelGetEof(WOLFSSH_CHANNEL*); WOLFSSH_API int wolfSSH_get_error(const WOLFSSH*);