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 6046189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:12:36+00:00 2026-05-23T07:12:36+00:00

int str_len = read(m_events[i].data.fd, buf, BUF_SIZE); I have this and I read data into

  • 0
int str_len = read(m_events[i].data.fd, buf, BUF_SIZE);

I have this and I read data into the buf declared like

char buf[BUF_SIZE];

What I am trying to do is that I am trying to get the data and hand it to the WorkHanndler which I defined and nothing more than just a thread pool.

And the function is

void ServerManager::addWork(int sender, char *data){
    Work* work = new Work(sender, data);
    m_workHandler->addWork(work);
}

So I need a char pointer which points to the data I just read. Since the buffer is defined as an array I won’t be able to pass that into the function.

Also, do you guys think this is a good idea in terms of server design? I am reading data from the buffer and don’t parse it and just hand to the raw data to the thread pool (insert into queue). The thread pool has a queue and five separate thread competes to get the job from the queue with mutex lock and condition variable. After finish the job then the separate thread will write the result to the output buffer. Please let me know if it has drawbacks and you guys have a better idea. 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-23T07:12:37+00:00Added an answer on May 23, 2026 at 7:12 am

    Only possible flaw I see right now could be inside the Work class: Ensure it creates its own copy of the buffer contents immediately in the constructor as it will be overwritten once new data arrives. Other than that it should work as expected (hard to judge without specific work to be done, etc.).

    Also there shouldn’t be an issue using the array when a pointer to the array’s elements’ type is required as the array is essentially just a pointer (code wise):

    char data[1024];
    char *pdata = data; // now data as well as pdata point to the first element
    // data[0] is the same as using *(pdata + 0)
    // data[1] is the same as using *(pdata + 1)
    

    If there’s some compiler warning or error, post the exact message. The only real difference between both variants to access arrays is that the compiler will know he’ll get a poiner to a whole array instead of a single instance when using char variable[] instead of char *variable.

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

Sidebar

Related Questions

In Guile 1.6.*, the function scm_istring2number(char *str,int strlen,int radix) does the work. However, this
Here is my code: std::string readString() { int strLen = Read<int>(); char* rawString =
I could do this in C#.. int number = 2; string str = Hello
int x = n / 3; // <-- make this faster // for instance
int main(void) { char tmp, arr[100]; int i, k; printf(Enter a string: ); scanf_s(%s,
Im trying to read in image file from a server , with the code
I have an assignment that is supposed to be written in C (not C++),
I'm trying to read in a list of files from another file. The file
I've read several discussions of passing char * in C. stackoverflow: passing-an-array-of-strings-as-parameter-to-a-function-in-c stackoverflow: how-does-an-array-of-pointers-to-pointers-work
I have a (seemingly) simple question to read in a string and print it

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.