IPC with sockets - PowerPoint PPT Presentation

1 / 40
About This Presentation
Title:

IPC with sockets

Description:

what exactly are sockets? working with sockets. how does the ... using a combination of 32-bit numbers and a port-number as address (e.g. 192.168.0.1:8088) ... – PowerPoint PPT presentation

Number of Views:298
Avg rating:3.0/5.0
Slides: 41
Provided by: filippols
Category:
Tags: ipc | sockets

less

Transcript and Presenter's Notes

Title: IPC with sockets


1
IPC with sockets
Linux Internals
  • sockets in the linux operating system

Filip Polsakiewicz
December, 18th 2001
2
topic overview
  • motivation why sockets?
  • what exactly are sockets?
  • working with sockets
  • how does the linux kernel implement sockets?
  • summary

3
topic overview
  • motivation why sockets?
  • what exactly are sockets?
  • working with sockets
  • how does the linux kernel implement sockets?
  • summary

4
topic overview
  • motivation why sockets?
  • what exactly are sockets?
  • working with sockets
  • how does the linux kernel implement sockets?
  • summary

5
topic overview
  • motivation why sockets?
  • what exactly are sockets?
  • working with sockets
  • how does the linux kernel implement sockets?
  • summary

6
topic overview
  • motivation why sockets?
  • what exactly are sockets?
  • working with sockets
  • how does the linux kernel implement sockets?
  • summary

7
motivation why sockets?
  • UNIX-Operating systems at first only supported
    using directional pipes for ipc
  • only related processes on the same machine were
    able to communicate
  • only one-way communication

8
motivation why sockets?
  • UNIX-Operating systems at first only supported
    using pipes for ipc
  • only related processes on the same machine were
    able to communicate
  • only one-way communication
  • networking was difficult since there were no
    standards for network interfaces
  • developing applications for network jobs was
    difficult (each network interface had to be
    implemented seperately)

9
motivation why sockets?
  • many research facilities developed solutions for
    these both problems
  • bidirectional pipes, named pipes
  • one of these solutions solved both Problems
    sockets

10
what are sockets
  • sockets are a connection-based type of ipc
  • sockets are an abstraction of the network
    interface and the network protocol
  • developers do not have to care about implementing
    hardware-specific details

11
what are sockets
  • sockets are a connection-based type of ipc
  • sockets are an abstraction of the network
    interface and the network protocol
  • developers do not have to care about implementing
    hardware-specific details

socket layer
Stream Socket
TCP/IP Protocol
network protocols
network interfaces
10 MBit/s Ethernet
12
what are sockets
process 1
process 2
KERNEL
socket
socket
13
general properties of sockets
  • connection-based
  • can have an address bound to them
  • use packets for data transmission
  • allow checking for errors
  • UNIX_STREAM and TCP
  • allow IPC in a network enviroment
  • allrounders
  • many protocols such as IPX, AX_25 and Appletalk
    are supported

14
general properties of sockets
  • connection-based
  • can have an address bound to them
  • use packets for data transmission
  • allow checking for errors
  • UNIX_STREAM and TCP
  • allow IPC in a network enviroment
  • allrounders
  • many protocols such as IPX, AX_25 and Appletalk
    are supported

15
general properties of sockets
  • connection-based
  • can have an address bound to them
  • use packets for data transmission
  • allow checking for errors
  • UNIX_STREAM and TCP
  • allow IPC in a network enviroment
  • allrounders
  • many protocols such as IPX, AX_25 and Appletalk
    are supported

16
general properties of sockets
  • connection-based
  • can have an address bound to them
  • use packets for data transmission
  • allow checking for errors
  • UNIX_STREAM and TCP
  • allow IPC in a network enviroment
  • allrounders
  • many protocols such as IPX, AX_25 and Appletalk
    are supported

17
general properties of sockets
  • connection-based
  • can have an address bound to them
  • use packets for data transmission
  • allow checking for errors
  • UNIX_STREAM and TCP
  • allow IPC in a network enviroment
  • allrounders
  • many protocols such as IPX, AX_25 and Appletalk
    are supported

18
general properties of sockets
  • connection-based
  • can have an address bound to them
  • use packets for data transmission
  • allow checking for errors
  • UNIX_STREAM and TCP
  • allow IPC in a network enviroment
  • allrounders
  • many protocols such as IPX, AX_25 and Appletalk
    are supported

19
different types of sockets
SOCKET
20
different types of sockets
  • UNIX Domain sockets
  • realized in memory
  • can be bound to an address which appears in the
    local filesystem (e.g. /tmp/mysocket)
  • if client and server are on the same machine,
    twice as fast as INET-sockets (see X-Server)
  • Internet (INET) sockets
  • implemented through the network
  • using a combination of 32-bit numbers and a
    port-number as address (e.g. 192.168.0.18088)
  • both types have in common once they are bound to
    an address they can be reached by other sockets

21
different types of sockets
  • UNIX Domain sockets
  • realized in memory
  • can be bound to an address which is a file
    appears in the local filesystem (e.g.
    /tmp/mysocket)
  • if client and server are on the same machine,
    twice as fast as INET-sockets (see X-Server)
  • Internet (INET) sockets
  • implemented through the network
  • using a combination of 32-bit numbers and a
    port-number as address (e.g. 192.168.0.18088)
  • both types have in common once they are bound to
    an address they can be reached by other sockets

address
port
22
different types of sockets
  • UNIX Domain sockets
  • realized in memory
  • can be bound to an address which appears in the
    local filesystem (e.g. /tmp/mysocket)
  • if client and server are on the same machine,
    twice as fast as INET-sockets (see X-Server)
  • Internet (INET) sockets
  • implemented through the network
  • using a combination of 32-bit numbers and a
    port-number as address (e.g. 192.168.0.18088)
  • both types have in common once they are bound to
    an address they can be reached by other sockets

23
different types of sockets
  • UNIX Domain sockets
  • realized in memory
  • can be bound to an address which appears in the
    local filesystem (e.g. /tmp/mysocket)
  • if client and server are on the same machine,
    twice as fast as INET-sockets (see X-Server)
  • Internet (INET) sockets
  • implemented through the network
  • using a combination of six 32-bit numbers and a
    port-number as address
  • both types have in common once they are bound to
    an address they can be reached by other sockets

We will concentrate on UNIX Domain sockets since
INET Sockets will be handled later
24
working with sockets (server)
sun_family sun_path
tells the kernel that the socket is now ready to
accept connections
listen(int fd, int backlog)
on an incoming connection
accept(int fd, struct sockaddr upeer_sockaddr,
int upeer_addrlen)
25
working with sockets (client)
26
communication
SERVER
CLIENT
socket()
bind()
listen()
socket()
connect()
accept()
write
read
read
write
close()
close()
27
some additional functions
  • socketpair()
  • creates two socket file descriptors and connects
    them to each other
  • similar to bidirectional pipes
  • shutdown(int fd, int how)
  • closes the socket file descriptor

28
some additional functions
  • socketpair()
  • creates two socket file descriptors and connects
    them to each other
  • simmilar to bidirectional pipes
  • shutdown(int fd, int how)
  • closes the socket file descriptor

29
netstat -a
Active UNIX domain sockets (servers and
established)Proto RefCnt Flags
Type State I-Node
Pathunix 1 STREAM
CONNECTED 2523 _at_0000000bunix 1
STREAM CONNECTED 2689
_at_0000000e unix 0 ACC STREAM
LISTENING 331 /var/run/mysqld/mysqld.so
ckunix 0 ACC STREAM LISTENING
46678 /dev/logunix 1
STREAM CONNECTED 2698
_at_00000010unix 1 STREAM
CONNECTED 225 _at_00000001unix 1
STREAM CONNECTED 237
_at_00000003unix 0 ACC STREAM
LISTENING 2686 /tmp/.X11-unix/X0unix
0 ACC STREAM LISTENING
2514 /var/lib/zope/var/Z2-pcgi.socunix 0
ACC STREAM LISTENING 395
/tmp/.font-unix/fs7100unix 1
STREAM CONNECTED 2699
/tmp/.X11-unix/X0unix 1
STREAM CONNECTED 2693 /tmp/.X11-unix/X0u
nix 1 STREAM
CONNECTED 2541 /dev/log
30
how are sockets implemented in the kernel
  • each of the socket functions introduced in
    earlier has a corresponding function in the
    kernel
  • socket() ? sys_socket()
  • bind ? sys_bind()
  • when the process calls a function the kernel
    executes the corresponding function which itself
    calls other functions

31
how are sockets implemented in the kernel
  • each of the socket functions introduced in
    earlier has a corresponding function in the
    kernel
  • socket() ? sys_socket()
  • bind ? sys_bind()
  • when the process calls a function the kernel
    executes the corresponding function which itself
    calls other functions

sock_write()
unix_sendmsg()
sys_write()
stream_sendmsg()
write()
32
data-structures
type
proto_ops

data
33
data-structures
type
proto_ops

data
34
data-structures
type
proto_ops

data
35
data-structures
type
proto_ops

data
36
summary
  • sockets are an abstraction of the actual hardware
    and protocol layers
  • sockets are connection-based
  • after a socket was bound to an address it can be
    reached by other sockets
  • communication of two sockets can be accomplished
    by using standard file IO functions

37
summary
  • sockets are an abstraction of the actual hardware
    and protocol layers
  • sockets are connection-based
  • after a socket was bound to an address it can be
    reached by other sockets
  • communication of two sockets can be accomplished
    by using standard file IO functions

38
summary
  • sockets are an abstraction of the actual hardware
    and protocol layers
  • sockets are connection-based
  • after a socket was bound to an address it can be
    reached by other sockets
  • communication of two sockets can be accomplished
    by using standard file IO functions

39
summary
  • sockets are an abstraction of the actual hardware
    and protocol layers
  • sockets are connection-based
  • after a socket was bound to an address it can be
    reached by other sockets
  • communication of two sockets can be accomplished
    by using standard file IO functions

40
thank you for your attention
Write a Comment
User Comments (0)
About PowerShow.com