tags:

views:

147

answers:

3

I can see it looks like an alias for an unsigned int pointer, right? Is it just like a pointer in memory? To what would it be actually pointing? Is it pointing to a struct? If yes, how is that struct defined? Is it just a number that is used by socket functions and does not map to a memory address?

+2  A: 

from wikipedia-

Generally, a file descriptor is an index for an entry in a kernel-resident data structure containing the details of all open files. In POSIX this data structure is called a file descriptor table, and each process has its own file descriptor table. The user application passes the abstract key to the kernel through a system call, and the kernel will access the file on behalf of the application, based on the key. The application itself cannot read or write the file descriptor table directly. link

ashika
+4  A: 

In Win32, a SOCKET data type is the same as a HANDLE, which is an integer used to refer to a kernel data structure of some kind. This kernel data structure is "opaque", which means that application programs do not need to (and in fact cannot) see the internals of the structure. All access to Win32 SOCKETs is done through Winsock API functions.

Note that in Win16, a SOCKET was not the same thing because there was no Win16 HANDLE type. However, Win32 kept the same type name for source compatibility.

Greg Hewgill
"Handle" defines what it is, despite this is not a regular Win32 HANDLE. Most HANDLEs are pointers to the objects they represent, SOCKET doesn't. It is more like an ID then a HANDLE.
Havenard
All Win32 HANDLEs are integer indexes into the kernel object table; they are not pointers as such.
Greg Hewgill
+2  A: 

You could check out the Linux source for socket.h, for instance. Although in the case of sockets (the type of which is not actually described in socket.h), a socket is a file descriptor, not unlike the return of open in C (which you don't use in day-to-day programming).

As to what is a file descriptor: at a very high level, it's typically just an int that the OS translates into a way to communicate with a file object, or a socket object for network communications, or a pipe to communicate between processes...

Mark Rushakoff