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

  • Home
  • SEARCH
  • 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 6223535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:30:24+00:00 2026-05-24T08:30:24+00:00

I am working on a network programming and I have this code void WorkHandler::workLoop(){

  • 0

I am working on a network programming and I have this code

void WorkHandler::workLoop(){
.
.
.

while(1){
    if(remainLength >= MAX_LENGTH)
        currentSentLength = send(client->getFd(), sBuffer, MAX_LENGTH, MSG_NOSIGNAL);
    else
        currentSentLength = send(client->getFd(), sBuffer, remainLength,MSG_NOSIGNAL);


if(currentSentLength == -1){
    log("WorkHandler::workLoop, connection has been lost \n");
    break;
}
sBuffer += currentSentLength;
remainLength -= currentSentLength;

if(remainLength == 0)
    break;
     }
}

Also, I am creating a child thread like this

bool WorkHandler::initThreads(){

for(int i=0; i < m_maxThreads; i++){
    pthread_t *thread(new pthread_t);
    m_workThreadList.push_back(thread);

    if(pthread_create(thread, NULL, runWorkThread, reinterpret_cast<void *>(this))!=0){
        log("WorkHandler::initThreads, pthread_create error \n");
        return false;
    }

    pthread_detach(*thread);
}

return true;

}

void* WorkHandler::runWorkThread(void *delegate){
    printf("WorkHandler::runWorkThread, called\n");

    WorkHandler *ptr = reinterpret_cast<WorkHandler*>(delegate);
    ptr->workLoop();
    return NULL;
}

I am running this code on gdb and it doesn’t blow up but it gets stuck at the second send function in the if then else loop. I put log statements every single line and it prints a log right above the second send function and stopped.

currentSentLength = send(client->getFd(), sBuffer, remainLength, MSG_NOSIGNAL);

What might cause this problem and how do I fix this issue?
Thanks in advance..

  • 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-05-24T08:30:25+00:00Added an answer on May 24, 2026 at 8:30 am

    With blocking IO send will block if the kernel buffer is full and will block untill the clients have read the data. Do you send large chunks? If so, check your client.

    If you don’t trust clients (they can abuse this to do denial of service attacks) there are a couple of ways to do this properly: poll (with timeout) on the sockets for writeability, send with timeout, use nonblocking I/O, …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a social network type project, as most social networks have,
I am looking for information on Windows network programming. Mainly how to get a
I am currently working on network software. It has one main class, server which
I am presently working on two different linux boxes in the same network. Now
I am writing an application that fetches data from MS AX Dynamics once-in-a-very-long-while The
Here is my scenario: A is a provisioning server and B is an client.
When working with audio playback I am used to the following pattern: one disk
I am working on a project that I will transfer webcam images on the
I hope you're all well. I'm wondering if you could help me or point
I've just started playing around with Knockout.js, and it seems really cool. What I

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.