Download presentation
Presentation is loading. Please wait.
Published byCharla Cameron Modified over 8 years ago
1
ioctl Operations
2
ioctl Function
3
Interface Configuration Netstat, ifconfig command 에서 사용
4
ARP Caching and Routing Table Operations ARP(Address Resolution Protocol) cache operations ARP: protocol(IP) address hardware address Routing table operations
5
fcntl Function Set socket for nonblocking I/O: F_SETFL, O_NONBLOCK Set socket for signal-driven I/O: F_SETFL, O_ASYNC Set socket owner: F_SETOWN Get socket owner: F_GETOWN
6
Fcntl, ioctl, and routing socket
7
Nonblocking I/O
8
Blocking and Nonblocking Sockets OperationBlockingNonblocking Input TCP no data available in socket receive buffer Returns immediately with error of EWOULDBLOCK UDP socket receive buffer is empty Output TCP no room in socket send buffer immediate error return if no room in socket send buffer, or returns # of bytes written if some room in socket send buffer UDP never blocks (no actual UDP socket send buffer) never blocks (Returns # of bytes written) accept() new connection is not available Returns immediately with error of EWOULDBLOCK connec t() TCP blocks for at least RTT Returns immediately with error of EINPROGRESS if connection not established, or returns OK(==0) if connection established immediately UDP never blocks (just store peer’s IP addr/port #)
9
Buffering for Nonblocking Read/Write Send buffer Receive buffer
10
Nonblocking str_cli nonblock/strclinonb.c:
11
Time Line of Nonblocking Example
12
A Simpler Version of str_cli using concurrent processes
13
A Simpler Version of str_cli using Threads
14
Clock Time Comparison of str_cli Sample case input file of 2000 lines 175msec RTT Stop-and wait:354.0 sec select and blocking I/O: 12.3 sec Nonblocking I/O: 6.9 sec Two processes with fork: 8.7 sec Threaded version: 8.5 sec 1 Simpler is better
15
Nonblocking connect Usage overlap other processing with three-way handshake(for RTT) establish multiple connections: popular with Web browsers shorten timeout for connection establishment(typically 75 sec) by using select with time limit specification Non blocking connect Returns immediately with an error of EINPROGRESS, but TCP three-way handshake continues check for either successful or unsuccessful completion of connection establishment using select If server is on the same host, connection establishment normally takes place immediately(returns 0) Many portability problems
16
Nonblocking Connect: Daytime Client lib/connect_nonb.c Shorten timeout
17
Nonblocking Multiple Connections: Web Client Establish a connection for reading a page Then, establish multiple connections for reading references in the page Using nonblocking connections Or using thread per connection
18
Nonblocking accept Use nonblocking accept Or, select for listening socket(may blocked) then, accept when listening socket is ready
19
Signal-Driven I/O
20
2 different ways to build a UDP server
21
Signal-Driven I/O for Sockets Steps for Signal-driven I/O establish SIGIO signal handler set socket owner for receiving signals fcntl(sockfd, F_SETOWN, getpid()); enable socket to signal-driven I/O ioctl(sockfd, FIOASYNC, &on); /* signal-driven I/O */ ioctl(sockfd, FIONBIO, &on); /* non-blocking I/O */ SIGIO signal is generated whenever for UDP socket a datagram arrives an asynchronous error occurs for TCP sockets Signal is generated too often not useful too many cases
22
UDP Echo Server using SIGIO (I) sigio/dgecho01.c
23
UDP Echo Server using SIGIO (II)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.