<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[wolfSSL - Embedded SSL Library — [SOLVED] WS_OVERFLOW_E when using wolfSSH_connect() with epoll]]></title>
		<link>https://www.wolfssl.com/forums/topic1984-solved-wsoverflowe-when-using-wolfsshconnect-with-epoll.html</link>
		<atom:link href="https://www.wolfssl.com/forums/feed-rss-topic1984.xml" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in [SOLVED] WS_OVERFLOW_E when using wolfSSH_connect() with epoll.]]></description>
		<lastBuildDate>Thu, 16 May 2024 21:45:24 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: [SOLVED] WS_OVERFLOW_E when using wolfSSH_connect() with epoll]]></title>
			<link>https://www.wolfssl.com/forums/post7643.html#p7643</link>
			<description><![CDATA[<p>This issue was fixed with <a href="https://github.com/wolfSSL/wolfssh/pull/565">PR #565</a>, back in late August, 2023. This fix was included in the release of <a href="https://github.com/wolfSSL/wolfssh/releases/tag/v1.4.15-stable">v1.4.15</a>.</p>]]></description>
			<author><![CDATA[null@example.com (john)]]></author>
			<pubDate>Thu, 16 May 2024 21:45:24 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7643.html#p7643</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] WS_OVERFLOW_E when using wolfSSH_connect() with epoll]]></title>
			<link>https://www.wolfssl.com/forums/post7642.html#p7642</link>
			<description><![CDATA[<p>Which version of wolfSSH are you using? I&#039;m going to assume v1.4.12, since that was released before your original post. I am seeing the WS_OVERFLOW_E error with that version. I&#039;m going to check to see if we explicitly fixed it, or what.</p>]]></description>
			<author><![CDATA[null@example.com (john)]]></author>
			<pubDate>Thu, 16 May 2024 20:20:04 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7642.html#p7642</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] WS_OVERFLOW_E when using wolfSSH_connect() with epoll]]></title>
			<link>https://www.wolfssl.com/forums/post7641.html#p7641</link>
			<description><![CDATA[<p>I&#039;m embarrassed. I apologize for forgetting about this and not following up.</p><p>I&#039;m probably as surprised as you about epoll and wolfSSH misbehaving like that. I&#039;m trying out your test program.</p>]]></description>
			<author><![CDATA[null@example.com (john)]]></author>
			<pubDate>Thu, 16 May 2024 20:05:37 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7641.html#p7641</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] WS_OVERFLOW_E when using wolfSSH_connect() with epoll]]></title>
			<link>https://www.wolfssl.com/forums/post7081.html#p7081</link>
			<description><![CDATA[<p>Hey,</p><p>I just wanted to ask if there is any update.</p><p>Thanks!</p>]]></description>
			<author><![CDATA[null@example.com (testwolverinebagel)]]></author>
			<pubDate>Mon, 10 Apr 2023 10:26:05 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7081.html#p7081</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] WS_OVERFLOW_E when using wolfSSH_connect() with epoll]]></title>
			<link>https://www.wolfssl.com/forums/post7048.html#p7048</link>
			<description><![CDATA[<p>Hey John,</p><p>I prepared a minimal example which shows the behavior I described earlier.<br /></p><div class="codebox"><pre><code>#include &lt;sys/socket.h&gt;
#include &lt;arpa/inet.h&gt;

#include &lt;fcntl.h&gt;
#include &lt;wolfssh/ssh.h&gt;
#include &lt;errno.h&gt;
#include &lt;sys/epoll.h&gt;

#define SSH_SERVER_ADDR &quot;192.168.188.69&quot;
#define SSH_USER &quot;myUsername&quot;
#define SSH_PASS &quot;myPassword&quot;

int sock = 0;
WOLFSSH_CTX* ctx = NULL;
WOLFSSH* ssh = NULL;

struct epoll_event events[5];

enum states
{
    CONNECTING,
    LOGIN,
    DONE
};

int currState = CONNECTING;

int setup_socket();

int connect_sock();

int get_socket_error();

int init_ssh();

int authCb(byte authType, WS_UserAuthData* authData, void* userData);

int login();

int main()
{
    // create nonblocking socket
    if(setup_socket() &lt; 0)
    {
        perror(&quot;Setting up socket failed&quot;);
        if(sock &gt; 0)
            close(sock);
        exit(0);
    }

    // call non-blocking connect
    if(connect_sock() &lt; 0)
    {
        perror(&quot;Connecting failed&quot;);
        close(sock);
        exit(0);
    }

    // initialize wolfssh
    if(init_ssh() &lt; 0)
    {
        printf(&quot;ssh error: %d&quot;, wolfSSH_get_error(ssh));
        if(ctx)
            wolfSSH_CTX_free(ctx);
        if(ssh)
            wolfSSH_free(ssh);
        close(sock);
        exit(0);
    }

    // setup epoll
    int epoll = epoll_create(1);

    struct epoll_event event;
    event.events = EPOLLIN | EPOLLOUT;
    event.data.fd = sock;
    if(epoll_ctl(epoll, EPOLL_CTL_ADD, sock, &amp;event) &lt; 0)
    {
        perror(&quot;epoll_ctl&quot;);
        wolfSSH_CTX_free(ctx);
        wolfSSH_free(ssh);
        close(sock);
        exit(0);
    }

    int nfds;
    int notDone = 1;
    while(notDone)
    {
        nfds = epoll_wait(epoll, events, sizeof(events), 3);
        if(nfds == -1)
        {
            perror(&quot;epoll_wait&quot;);
            break;
        }

        int ret;
        for(int n = 0; n &lt; nfds; ++n)
        {
            if(events[n].data.fd == sock &amp;&amp; (events[n].events &amp; (EPOLLIN | EPOLLOUT)))
            {
                switch(currState)
                {
                    case CONNECTING:
                        ret = get_socket_error();
                        if(ret != 0 &amp;&amp; ret != EINPROGRESS)
                        {
                            printf(&quot;Failed to connect, %s\n&quot;, strerror(ret));
                            currState = DONE;
                        }
                        else if(ret != EINPROGRESS)
                        {
                            printf(&quot;Connected\n&quot;);
                            currState = LOGIN;
                        }
                        else
                        {
                            currState = CONNECTING;
                        }
                        break;
                    case LOGIN:
                        ret = login();
                        if(ret == WS_SUCCESS)
                        {
                            printf(&quot;Login success&quot;);
                            currState = DONE;
                        }
                        else if(ret == WS_WANT_READ || ret == WS_WANT_WRITE)
                        {
                            // repeat calling login()
                            currState = LOGIN;
                        }
                        else
                        {
                            printf(&quot;Login failed, code %d&quot;, wolfSSH_get_error(ssh));
                            currState = DONE;
                        }
                        break;
                    case DONE:
                        notDone = 0;
                        break;
                }
            }
        }
    }

    wolfSSH_shutdown(ssh);
    wolfSSH_CTX_free(ctx);
    wolfSSH_free(ssh);
    close(sock);

    return 0;
}

int setup_socket()
{
    sock = socket(AF_INET, SOCK_STREAM, 0);
    if(sock &lt; 0)
        return -1;

    // set non-blocking
    if(fcntl(sock, F_SETFL, O_NONBLOCK | fcntl(sock, F_GETFL, 0)) &lt; 0)
        return -1;

    return 0;
}

int connect_sock()
{
    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(22);
    inet_pton(AF_INET, SSH_SERVER_ADDR, &amp;(addr.sin_addr));

    if(connect(sock, (struct sockaddr*)(&amp;addr), sizeof(addr)) &lt; 0 &amp;&amp; errno != EINPROGRESS)
        return -1;

    return 0;
}

int get_socket_error()
{
    int err;
    socklen_t size = sizeof(err);
    int ret = getsockopt(sock, SOL_SOCKET, SO_ERROR, &amp;err, &amp;size);
    if(ret &lt; 0)
        return ret;

    return err;
}

int init_ssh()
{
    wolfSSH_Init();

    ctx = wolfSSH_CTX_new(WOLFSSH_ENDPOINT_CLIENT, NULL);
    if(!ctx)
        return -1;

    ssh = wolfSSH_new(ctx);
    if(!ssh)
        return -1;

    int ret = wolfSSH_set_fd(ssh, sock);
    if(ret != WS_SUCCESS)
        return -1;

    // set channel to shell
    ret = wolfSSH_SetChannelType(ssh, WOLFSSH_SESSION_SHELL, NULL, 0);
    if(ret != WS_SUCCESS)
        return -1;

    // set auth callback
    wolfSSH_SetUserAuth(ctx, authCb);
    // set callback data
    wolfSSH_SetUserAuthCtx(ssh, NULL);
    // set username
    wolfSSH_SetUsername(ssh, SSH_USER);

    return 0;
}

int authCb(byte authType, WS_UserAuthData* authData, void* userData)
{

    if(authType == WOLFSSH_USERAUTH_PASSWORD)
    {
        authData-&gt;sf.password.password = (byte*)(SSH_PASS);
        authData-&gt;sf.password.passwordSz = strlen(SSH_PASS);
    }
    else
    {
        return WOLFSSH_USERAUTH_REJECTED;
    }

    return WOLFSSH_USERAUTH_SUCCESS;
}

int login()
{
    int ret = wolfSSH_connect(ssh);

    // Here comes th odd part. If you remove the call to usleep(),
    // WS_OVERFLOW_E is returned by wolfssh.
    // With usleep it works perfectly.
    usleep(10000);

    if(ret != WS_SUCCESS)
    {
        return wolfSSH_get_error(ssh);
    }

    return WS_SUCCESS;
}</code></pre></div><p>Thank you very much!</p>]]></description>
			<author><![CDATA[null@example.com (testwolverinebagel)]]></author>
			<pubDate>Sun, 26 Mar 2023 09:07:25 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7048.html#p7048</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] WS_OVERFLOW_E when using wolfSSH_connect() with epoll]]></title>
			<link>https://www.wolfssl.com/forums/post7043.html#p7043</link>
			<description><![CDATA[<p>testwolverinebagel:</p><p>We don&#039;t have an example that uses epoll. Our example client is using select() in the function NonBlockSSH_connect(). Can you share with me the code you are using for your connect? You can send it to support@wolfssl.com if you don&#039;t want to post it here.</p><p>--John</p>]]></description>
			<author><![CDATA[null@example.com (john)]]></author>
			<pubDate>Thu, 23 Mar 2023 17:25:32 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7043.html#p7043</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] WS_OVERFLOW_E when using wolfSSH_connect() with epoll]]></title>
			<link>https://www.wolfssl.com/forums/post7041.html#p7041</link>
			<description><![CDATA[<p>Hi Eric,</p><p>Thanks for your reply. I am compiling for x86 &amp; x64 architectures, but I am using uclibc. As I said it actually works if I add a call to sleep() after wolfSSH_connect() and sometimes if I enable the wolfssh debug log.</p>]]></description>
			<author><![CDATA[null@example.com (testwolverinebagel)]]></author>
			<pubDate>Wed, 22 Mar 2023 21:05:04 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7041.html#p7041</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] WS_OVERFLOW_E when using wolfSSH_connect() with epoll]]></title>
			<link>https://www.wolfssl.com/forums/post7039.html#p7039</link>
			<description><![CDATA[<p>Hi testwolverinebagel,</p><p>Thanks for joining the wolfSSL Forums. That is odd. Is this on an embedded platform that may be delayed while trying to negotiate a secure connection?</p><p>I will check with the team to see if we have a wolfSSH example client set up with EPOLL that you could review.</p><p>Kind regards,<br />Eric - wolfSSL Support</p>]]></description>
			<author><![CDATA[null@example.com (embhorn)]]></author>
			<pubDate>Wed, 22 Mar 2023 18:23:04 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7039.html#p7039</guid>
		</item>
		<item>
			<title><![CDATA[[SOLVED] WS_OVERFLOW_E when using wolfSSH_connect() with epoll]]></title>
			<link>https://www.wolfssl.com/forums/post7035.html#p7035</link>
			<description><![CDATA[<p>Hey,</p><p>I&#039;m having trouble figuring out how to use wolfSSH_connect() with epoll. wolfSSH_connect() is called again on every EPOLLIN/EPOLLOUT event if the previous call to the function returned WS_WANT_READ/WS_WANT_WRITE. But I always get an WS_OVERFLOW_E error after the server sent his DH Key Exchange Reply. </p><p>It works if I add a delay of about 100ms after (not before!) the call to wolfSSH_connect(), but that somehow defeats the purpose of using non-blocking sockets.</p><p>Am I using the function in a wrong way?</p>]]></description>
			<author><![CDATA[null@example.com (testwolverinebagel)]]></author>
			<pubDate>Wed, 22 Mar 2023 17:10:16 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7035.html#p7035</guid>
		</item>
	</channel>
</rss>
