Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9130303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:56:28+00:00 2026-06-17T07:56:28+00:00

All :) I have some piece of code with correctly works on Linux and

  • 0

All 🙂

I have some piece of code with correctly works on Linux and WinXP

int FlowTestIP::do_recvfrom()
{
    int ret;
    struct timeval timeout;// = {2, 0};
    timeout.tv_sec = 2;
    timeout.tv_usec = 0;

    fd_set rfds;
    while(running) {
            FD_ZERO(&rfds);
            FD_SET(m_socket, &rfds);
            ret = select(m_socket + 1, &rfds, 0, 0, &timeout);
            cout << "// select ret = " << ret << " (errno = " << errno << ")" << endl;
            if (ret == -1 || ret == 0) {
                    if (!(ret == 0 && errno == 0))
                            cout << "select ret = " << ret << " (errno = " << errno << ")" << endl;
                    return ret;
            }
            if (FD_ISSET(m_socket, &rfds)) {
                    cout << WSAGetLastError() << endl;
                    break;
            }
    }
    return recvfrom(m_socket, in_buf, mtu, 0, (struct sockaddr *)&si_other, (socklen_t *)&otherAddrSize);
}

But in Windows 7 in continues to loop even when client apptication is exited.
Bad output is

…
// select ret = 1 (errno = 0)
0
// select ret = 1 (errno = 0)
0
// select ret = 1 (errno = 0)
0
FTControlServerThread::run
FTControlServerThread::recieved
pkt->ft_tos = UCHAR_MAX
QFuture::waitForFinished()
client alive true
// select ret = 1 (errno = 0)
0
// select ret = 1 (errno = 0)
0
// select ret = 1 (errno = 0)
0

normaly (on WinXP and Linux) output will be

…
// select ret = 1 (errno = 0)
0
// select ret = 1 (errno = 0)
0
// select ret = 1 (errno = 0)
0
FTControlServerThread::run
FTControlServerThread::recieved
pkt->ft_tos = UCHAR_MAX
QFuture::waitForFinished()
client alive true
QFuture::finished

And that is what I am waiting from it.

Has anyone encountered with such a misbehaviour?

Thanks in advance!

P.S. As @JoachimPileborg asked to show how I call this function:

FlowTest::recv(char *payload, size_t size)  
{  
...  
    while (running) {  
        len = do_recvfrom(); // it virtual method of class FlowTest  
        if (len == -1 || len == 0) {  
            return len;  
        }  

        if (running && !transport_recv_helper()) {  
            continue;  
        } else {  
            break;  
        }  
    }  
...  
}  

and recv is called from server GUI

void FlowTestServer::runTest(FlowTestServerHelper handler)
{
...
        if ((ret = server->recv(rcvdData, (size_t *)&size)) == -1 || ret == 0 || size == 0) {
            if (server_busy == 0)
                break;
            cout << "can't receive data (size == " << size << "; ret = " << ret << ")" << endl;
            continue;
        }
...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:56:29+00:00Added an answer on June 17, 2026 at 7:56 am

    Firstly: Using cout is allowed to reset errno. It doesn’t usually, but it can, especially on first use when it has to set up the locale. You need to save the value of errno in a temp variable, or use fprintf and friends – as a C lib function POSIX controls its behavior.

    Secondly: In Windows, you need to use WSAGetLastError() not errno.

    I suggest you make a macro sock_errno which will be (errno) on Linux/unix, and (WSAGetLastError()) on Windows. That will enable to you to code in a platform independent manner.

    • See here for more: http://msdn.microsoft.com/en-us/library/windows/desktop/ms737828(v=vs.85).aspx
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some C# code which programatically loops over all the cells in the
I have this piece of code I found on some blog, that's supposed to
I have some tables. These tables all have one column in common called 'classified_id':
I am creating a series of UserControls that all have some similar business logic.
How do you determine if all hash keys have some value ?
I have some source codes to display all file names in a UITablView I
I have some data structures: all_unordered_m is a big vector containing all the strings
I have some special parameters to all my wcf service methods that are handled
I have some classes that are used for Styling and all of them display
I have some download implementation which allows me to export all data from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.