Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What really is the SOCKET type?

Tags:

c++

sockets

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?

like image 755
devoured elysium Avatar asked Dec 17 '22 06:12

devoured elysium


2 Answers

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.

like image 196
Greg Hewgill Avatar answered Dec 27 '22 23:12

Greg Hewgill


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

like image 44
ashika Avatar answered Dec 28 '22 00:12

ashika