What is a SOCKET type?

I see it looks like an alias for an unsigned int pointer, right? Is it like a pointer in memory? What will this actually indicate? Indicates structure? If so, how is this structure determined? Is it just a number that is used by socket functions and not mapped to a memory address?

+2


source to share


3 answers


In Win32, the data type is the SOCKET

same as the type HANDLE

, which is an integer used to denote some kind of kernel data structure. This kernel data structure is "opaque", which means that applications do not need (and in fact cannot) see the internals of the structure. All access to Win32 SOCKET

is through the Winsock API functions.



Note that in Win16 a is SOCKET

not the same because there was no Win16 type HANDLE

. However, Win32 has kept the same type name for compatibility with the source code.

+7


source


from Wikipedia -



Typically, a file descriptor is an index to be written to a resident data structure containing 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 via a system call and the kernel will access the file on behalf of the key-based application. the application itself cannot read or write the file descriptor table directly. link

+2


source


You can check the Linux source for socket.h for example. Although in the case of sockets (which are not actually described in socket.h), the socket is a file descriptor, as opposed to returning open

to C (which you don't use day-to-day programming).

As for the file descriptor : at a very high level, it is usually just an int, which the OS translates into a way to communicate with a file object or socket object for network communication, or with a communication channel between processes ...

+2


source







All Articles