?
=?ISO-8859-1?Q?Ren=E9_Kjellerup?=
Hi all,
this is my first post to 'comp.lang.c++'
and I have some trouble with File Descriptors and C++
I use gcc/g++ on a Linux Mandrake 9.2 and a OpenBSD 3.4
and when I compile this code it doesn't complain:
//--- file01.c plain C code
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(void) {
int c_fd;
int s_fd = socket(AF_INET,SOCK_STREAM,0);
sockaddr_in server;
char buf[80];
.... // setting up the socket;
listen(s_fd,5);
while(1) {
c_fd = accept(s_fd,0,0);
if((fork()) == 0) {
int rbuf;
close(s_fd); // child do not need to listen
do {
bzero(buf, sizeof(buf));
rbuf = read(c_fd, buf, sizeof(buf));
if(rbuf == 0) {
close(c_fd);
continue;
} else {
// misc. action that the server does upon receiving data.
// among other things using the function: write(c_fd,buf,sizeof(buf));
// on more
}
} while(rbuf !=0);
exit(0);
} else {
close(c_fd);
}
}
}
// --- file01.c EOF
^
|
This works, but I'd like to use C++ simpler file streams,
but when I try to compile the same code as C++ then the functions;
read(), write(), and close() are not declared.
Is it correct to assume that file descriptors are not included in C++?
Is there a header that C++ can use to include them (or just these
functions)?
I'm grateful for any info on the subject, even if it means I have to
read up on some things.
Yours René
this is my first post to 'comp.lang.c++'
and I have some trouble with File Descriptors and C++
I use gcc/g++ on a Linux Mandrake 9.2 and a OpenBSD 3.4
and when I compile this code it doesn't complain:
//--- file01.c plain C code
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(void) {
int c_fd;
int s_fd = socket(AF_INET,SOCK_STREAM,0);
sockaddr_in server;
char buf[80];
.... // setting up the socket;
listen(s_fd,5);
while(1) {
c_fd = accept(s_fd,0,0);
if((fork()) == 0) {
int rbuf;
close(s_fd); // child do not need to listen
do {
bzero(buf, sizeof(buf));
rbuf = read(c_fd, buf, sizeof(buf));
if(rbuf == 0) {
close(c_fd);
continue;
} else {
// misc. action that the server does upon receiving data.
// among other things using the function: write(c_fd,buf,sizeof(buf));
// on more
}
} while(rbuf !=0);
exit(0);
} else {
close(c_fd);
}
}
}
// --- file01.c EOF
^
|
This works, but I'd like to use C++ simpler file streams,
but when I try to compile the same code as C++ then the functions;
read(), write(), and close() are not declared.
Is it correct to assume that file descriptors are not included in C++?
Is there a header that C++ can use to include them (or just these
functions)?
I'm grateful for any info on the subject, even if it means I have to
read up on some things.
Yours René