Sockets for Inter process communication
Socket programming interfaces provides communication via a network as well as locally on a single computer. Example is INET daemon which waits for incoming network service requests and then call the appropriate service program using the socket file descriptor as standard input and output.
Implementation of Unix domain sockets
- Represented by a kernel data structure socket
- Socket specific functions like Socket(), setsockout()
- The functions are implemented with a single system call socketcall which calls all the necessary functions by reference to the first parameter. The file operation read(), write(), poll(), ioctl(), lseek(), close() are called directly
- Operations of unix domain sockets
- long sys_socket(int family, int type, int protocol);// creates a socket file descriptor
- long sys_connect(int fd, struct sockaddr * uservaddr, int addrlen); //bind the socket to the unix domain address with specified length
- long sys_listen(int fd, int backlog);//checks whether any connections are being accepted at the server address.
- long sys_accept(int fd, struct sockaddr *upeer_sockaddr, int *upeer_addrlen));//server informs the kernel that the connections are being accepted from now on
- long sys_getsockname(int fd, struct sockaddr *usockaddr, int *usockaddr_len); //the address bound to the socket is returned.
- long sys_shutdown(int fd, int how); //to shutdown but status to be given that whether the sending and receiving still allowed
- sending and receiving from the sockets
- Messages can be sent either as a datagram or stream of bytes
- long sys_send(int fd, void *buff, int len, unsigned flags);
- long sys_sendmsg(int fd, struct msghdr *msg, unsigned int flags);
- long sys_recv(int fd, void *buff, int len, unsigned flags);
- long sys_recvmsg(int fd, struct msghdr *msg, unsigned int flags)