Socket recv receiving 0s

Hello,

I am working out an issue bringing a simple sockets conversation online. Need a little input.

I am configuring a socket server to run on an ARM processor, with C/C++ in the GCC toolchain. Using sys/socket.h as the basis, etc, etc.

The server socket is configured to accept connections non-blocking (async), and I have succeeded in connecting a client to the server socket over the wire to a Windows client.

When I attempt to wire up receive, I am finding that the client session, generated from the accept call, is always receiving data.

I don't know why, it's always 0's and I never see the client-sent data. Which the server then echos the data back. I am monitoring this over Wireshark, so I am pretty clear what's being sent/received.

This is targeting a custom hardware platform, so it is entirely plausible that we've got some sort of hardware issue we're contending with.

However, everything else being equal and this isn't the case, what would cause something like this to occur?

My receive routine is this: buffer_type is defined as std::vector<unsigned char>.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
int socket::recv(buffer_type& buffer) const {

    size_t buffer_cap_ = buffer.capacity();
    byte_type buffer_[buffer_cap_];

    auto cout_flags_ = std::cout.flags();

    std::cout << "recv: buffer_cap_: " << buffer_cap_ << std::endl;

    ::memset(buffer_, 0, buffer_cap_);
    int status_ = ::recv(m_sock, buffer_, buffer_cap_, 0);

    int result_ = verify_error_code(status_, "Could not read from socket.");

    if (result_ > 0) {
        for (int i = 0; i < status_; ++i) {
            buffer.push_back(buffer_[i]);
        }

        std::cout << "recv: " << "count: " << buffer.size() << " : ";
        std::cout << std::hex << std::setw(2) << std::setfill('0') << std::setiosflags(std::ios::showbase);
        for (auto& x : buffer) {
            std::cout << " " << static_cast<int>(x);
        }
        std::cout << std::resetiosflags(std::ios::showbase) << std::endl;
    }

    std::cout.flags(cout_flags_);

    return result_;
}


Thank you...

Regards,

Michael Powell
Last edited on
What's the value of status_?

That one at a time push_back of the content is inefficient. Have you considered bcopy or memcpy?
Topic archived. No new replies allowed.