Unix Programming - small prob with socket

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > February 2005 > small prob with socket





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author small prob with socket
puzzlecracker

2005-02-21, 6:00 pm

In the function msg_receive, fd is a socket connected to a remote
Internet client. What is wrong with msg_receive? Suggest a fix.
#define MAXVALS 65536

typedef struct _msg_t {
unsigned int num;
unsigned int values[MAXVALS];
} msg_t;

int msg_receive (int fd, msg_t *m)
{
size_t sz = sizeof (unsigned int);
assert (m);
if (read (fd, (void *)&m->num, sz) < sz)
return -1;
return read (fd, (void *)&m->values, sz * m->num);
}

Chris McDonald

2005-02-21, 6:00 pm

"puzzlecracker" <ironsel2000@gmail.com> writes:

>In the function msg_receive, fd is a socket connected to a remote
>Internet client. What is wrong with msg_receive? Suggest a fix.
> #define MAXVALS 65536


> typedef struct _msg_t {
> unsigned int num;
> unsigned int values[MAXVALS];
> } msg_t;


> int msg_receive (int fd, msg_t *m)
> {
> size_t sz = sizeof (unsigned int);
> assert (m);
> if (read (fd, (void *)&m->num, sz) < sz)
> return -1;
> return read (fd, (void *)&m->values, sz * m->num);
> }


More homework?
puzzlecracker

2005-02-21, 6:00 pm


Chris McDonald wrote:
> "puzzlecracker" <ironsel2000@gmail.com> writes:
>
>
>
>
> More homework?


that is from inteview? ))) too old for hws

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com