Re: C Sockets Newbie: Easy question
From: Francesco Moi (francescomoi_at_europe.com)
Date: 04/17/04
- Next message: phil-news-nospam_at_ipal.net: "Re: multi-threads writing to single socket simultanously."
- Previous message: kissdadog: "!!!! A chance of a lifetime !!!"
- In reply to: Lew Pitcher: "Re: C Sockets Newbie: Easy question"
- Next in thread: Barry Margolin: "Re: C Sockets Newbie: Easy question"
- Reply: Barry Margolin: "Re: C Sockets Newbie: Easy question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 17 Apr 2004 08:13:39 -0700
Thank you very much both.
I was checking some codefiles and found lines like:
---
rv = read(infd, outb, sizeof(outb))
send(fd, outb, strlen(outb), 0)
sendfile(fd, infd, 0, curstat.st_size)
---
and I thought that they ware related with Sockets.
Regards.
Lew Pitcher <Lew.Pitcher@td.com> wrote in message news:<6bWfc.34317$vF3.1971403@news20.bellglobal.com>...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Francesco Moi wrote:
>
> | I was trying to learn to program Sockets in C and found this
> | exam question:
>
> If this is an exam question for a sockets course, then the examiner is
> examining the wrong subject. The code fragment below has nothing to do
> with sockets, and everything to do with unix file handling.
>
> | ------------------//----------------------
> | Explain what is happening in the following code segment
> |
> | int fd;
> | fd = open("~/myfile",O_RDONLY);
> | if(fd==-1)
> | {
> | /* Some code */
> | exit(1);
> | }
> | --------------//------------------------
>
> fd is a 'file descriptor'
>
> open() attempts to the named file, with the named mode, and returns
> either the file descriptor of the open file (which is a small number
> greater than -1) or a -1 to indicate an error.
>
> the if statement checks the file descriptor returned by the open()
> function, and if it is -1 (that is to say, open() failed to open the
> file), the if statement executes the 'true' branch of the test.
>
> The true branch does some things ("/* some code */"), then invokes the
> exit() function to hard-terminate the process. The exit() function takes
> as its argument, a number (in this case, 1) which will be given to the
> OS as the process' termination code. exit() does not return, but
> instead, causes the process to terminate.
>
> So, this is prototypical code for an "abort the program if the file
> can't be opened for read access" logic segment, and has nothing directly
> to do with sockets programming.
>
> Aside: open() will attempt to open the named file. That file is, in this
> case, the file "myfile" in the "~" subdirectory of the process' current
> working directory.
>
> | I found in some codetexts 'fd' and 'outb', what are they?
>
> It's impossible to tell, given the amount of detail you've supplied.
> 'fd' probably is the file descriptor returned by open(), but it /may/ be
> used as a socket descriptor.
>
> 'outb' probably is an output buffer, but may be a reference to a
> function outb() which /may/ output a single 8-bit byte to a specified
> output port.
>
> | Where can find I resources to learn C Sockets?
>
> Like Barry said, "Unix Network Programming" by Stevens.
>
> I'd also suggest that you pick up a couple of books on Unix programming.
> "Advanced Programming in the Unix Environment" may be too advanced for
> you at the moment, but it's essential for anyone developing Unix code at
> the level of sophistication that sockets implies.
> - --
>
> Lew Pitcher, IT Consultant, Enterprise Application Architecture
> Enterprise Technology Solutions, TD Bank Financial Group
>
> (Opinions expressed here are my own, not my employer's)
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.4 (MingW32)
>
> iD8DBQFAgC9BagVFX4UWr64RAskcAKDHzCC/1vMxr//T5q0MKKlhBWqifQCgpKpn
> 03AJNWkIrGO/UTJd2WanG98=
> =W80J
> -----END PGP SIGNATURE-----
- Next message: phil-news-nospam_at_ipal.net: "Re: multi-threads writing to single socket simultanously."
- Previous message: kissdadog: "!!!! A chance of a lifetime !!!"
- In reply to: Lew Pitcher: "Re: C Sockets Newbie: Easy question"
- Next in thread: Barry Margolin: "Re: C Sockets Newbie: Easy question"
- Reply: Barry Margolin: "Re: C Sockets Newbie: Easy question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|