More on Socket API. How to Place Timeouts on Sockets (1)  Using SIGALRM signal Connection timeout 기간의 축소 Response timeout advio/dgclitimeo3.clib/connect_timeo.c.

Slides:



Advertisements
Similar presentations
Socket Options. abstraction Introduction getsockopt and setsockopt function socket state Generic socket option IPv4 socket option ICMPv6 socket option.
Advertisements

CCNA2 Module 4. Discovering and Connecting to Neighbors Enable and disable CDP Use the show cdp neighbors command Determine which neighboring devices.
Chapter 12 Transport protocols. Outline 12.1 introduction 12.2 TCP/IP protocol suite.
I/O Models Satish Krishnan. I/O Models Blocking I/O Non-blocking I/O I/O Multiplexing Signal driven I/O Asynchronous I/O.
Multicasting - Part II© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
Sockets CS 3516 – Computer Networks. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Distributed Computing Systems Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Copyright 1999, S.D. Personick. All Rights Reserved. Telecommunications Networking II Lecture 32 Transmission Control Protocol (TCP) Ref: Tanenbaum pp:
Socket Programming.
Multimedia Networking Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
CS3771 Today: network programming with sockets  Previous class: network structures, protocols  Next: network programming Sockets (low-level API) TODAY!
Socket Options Jari Kellokoski. Introduction So far we have discovered some basic usage of socket With socket options we control sockets more suitable.
1 K. Salah Module 6.1: TCP Flow and Congestion Control Connection establishment & Termination Flow Control Congestion Control QoS.
TCP. Learning objectives Reliable Transport in TCP TCP flow and Congestion Control.
Computer Network Architecture and Programming
Operating Systems Sockets. Outline F Socket basics F TCP sockets F Socket details F Socket options F Final notes F Project 3.
Socket option Getsockopt ou setsockopt fcntl ioctl.
Gursharan Singh Tatla Transport Layer 16-May
Process-to-Process Delivery:
1 Chapter Internetworking Part 4 (Transport Protocols, UDP and TCP, Protocol Port Numbers)
1 Transport Layer Computer Networks. 2 Where are we?
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
TCP Timers Chia-tai Tsai Introduction The 7 Timers for each Connection Connection-Establishment Timer Establish a new connection.
Socket Options –Four functions define the API for ‘get’ and ‘setting’ socket options. We will cover those aspects which address generic, IPv4, TCP UDP.
6.1. Transport Control Protocol (TCP) It is the most widely used transport protocol in the world. Provides reliable end to end connection between two hosts.
1 © 2003, Cisco Systems, Inc. All rights reserved. CCNA 2 Module 9 Basic Router Troubleshooting.
TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong.
CS332, Ch. 26: TCP Victor Norman Calvin College 1.
Section 5: The Transport Layer. 5.2 CS Computer Networks John Mc Donald, Dept. of Computer Science, NUI Maynooth. Introduction In the previous section.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 2.5 Internetworking Chapter 25 (Transport Protocols, UDP and TCP, Protocol Port Numbers)
Copyright 2002, S.D. Personick. All Rights Reserved.1 Telecommunications Networking II Topic 20 Transmission Control Protocol (TCP) Ref: Tanenbaum pp:
TCP1 Transmission Control Protocol (TCP). TCP2 Outline Transmission Control Protocol.
Chapter 12 Transmission Control Protocol (TCP)
Programming with TCP – III 1. Zombie Processes 2. Cleaning Zombie Processes 3. Concurrent Servers Using Threads  pthread Library Functions 4. TCP Socket.
1 TCP: Reliable Transport Service. 2 Transmission Control Protocol (TCP) Major transport protocol used in Internet Heavily used Completely reliable transfer.
Chapter 2 Applications and Layered Architectures Sockets.
7.9 TCP Socket Options 7.10 SCTP Socket Options 7.11 fcntl Function 7.12 Summary 報告者 : 梁凱鈞.
More on Socket API. More on Socket I/O Functions  Scatter read and gather write.
TELE 402 Lecture 10: Unix domain … 1 Overview Last Lecture –Daemon processes and advanced I/O functions This Lecture –Unix domain protocols and non-blocking.
Sockets For Clients Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
Netprog: Advanced Sockets Programming1 Advanced Sockets Programming Ref: Chapter 7,11,21,22.
Advanced Sockets API-II Vinayak Jagtap
I/O Multiplexing. TCP Echo Client: I/O operation is sequential !! tcpcliserv/tcpcli01.c: lib/str_cli.c: TCP Client TCP Server stdin stdout fgets fputs.
1 Socket Options Ref: Chapter 7. 2 Socket Options Various attributes that are used to determine the behavior of sockets.Various attributes that are used.
TELE 402 Lecture 9: Daemon … 1 by Dr Z. Huang Overview Last Lecture –Broadcast and multicast This Lecture –Daemon processes and advanced I/O functions.
Socket options: a summary –Tcp options, ip options and general socket options can be examined and sometimes modified. getsockopt, setsockopt routines Some.
Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified.
Today’s topic: UDP Reliable communication over UDP.
UDP Sockets Chap 8, 14, 22. Elementary UDP Sockets Chap 8.
1 Socket Options getsockopt and setsockopt functions Check options and obtain default values Generic socket options IPv4 socket options IPv6 socket options.
TCP Client-Server Example
ECE 4110 – Internetwork Programming
CMPT 471 Networking II Network Programming © Janice Regan,
I/O Multiplexing Chap 6. I/O Models  Blocking I/O Model  Nonblocking I/O Model  I/O Multiplexing Model  Signal Driven I/O Model  Asynchronous I/O.
McGraw-Hill Chapter 23 Process-to-Process Delivery: UDP, TCP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
TCP/IP1 Address Resolution Protocol Internet uses IP address to recognize a computer. But IP address needs to be translated to physical address (NIC).
11 CS716 Advanced Computer Networks By Dr. Amir Qayyum.
Client/Server Design Issues Based on Java Network Programming and Distributed Computing, Chapter 6 Also Online Java Tutorial, Sun.
3. END-TO-END PROTOCOLS (PART 1) Rocky K. C. Chang Department of Computing The Hong Kong Polytechnic University 22 March
1 Chapter 24 Internetworking Part 4 (Transport Protocols, UDP and TCP, Protocol Port Numbers)
IPv4 socket option Level => IPPROTO_IP
Socket Option.
5. End-to-end protocols (part 1)
Process-to-Process Delivery:
Chapter 07. Socket Options.
Advanced Sockets Programming
Process-to-Process Delivery: UDP, TCP
Computer Networks Protocols
Socket options: a summary
Advanced UNIX programming
Presentation transcript:

More on Socket API

How to Place Timeouts on Sockets (1)  Using SIGALRM signal Connection timeout 기간의 축소 Response timeout advio/dgclitimeo3.clib/connect_timeo.c alarm() 은 초 단위 setitimer() 는 micro sec 단위 설정 가능 ( 실제는 msec 단위로 동작 )

How to Place Timeouts on Sockets (2)  Using select with timeout advio/dgclitimeo1.c lib/readable_timeo.c

How to Place Timeouts on Sockets (3)  Using SO_RCVTIMEO and SO_SNDTIMEO socket options  Caution: timeout applies to all I/O operations for the socket descriptor advio/dgclitimeo2.c

More on Socket I/O Functions  recv and send (only for sockets)  Scatter read and gather write

More Advanced Socket I/O Functions

Ancillary data - cmsghdr Structure

Socket I/O Summary

Socket and Standard I/O  Buffering in Standard I/O library  fully buffered: all stream except for terminal devices  line buffered : terminal devices  unbuffered: stderr  Caution  Socket 에 standard I/O functions(fgets, fputs) 를 쓰면 fully buffered 됨

Socket Options

getsockopt and setsockopt Functions

Generic Socket Options(1)  SO_BROADCAST  Enable the ability of the process to send broadcast messages  Application must set this option before broadcasting  SO_DEBUG  Kernel keeps track of detailed information about all the packets sent or received by TCP for the socket  SO_DONTROUTE  Bypass the normal routing mechanism  The packet is directed to the appropriate local interface. If the local interface cannot be determined (i.e. destination is not on the same network), ENETUNREACH is returned.  SO_ERROR  Get the value of pending error  Socket 에 error 가 발생하면, so_error (pending error) 에 먼저 setting 하고 나서 errno 에 setting 함

Generic Socket Options(2)  SO_KEEPALIVE  Enforce TCP to send a keepalive probe automatically to the peer if no data has been exchanged for 2 hours (to detect if the peer host crashes)  Peer’s response is either  ACK: everything is OK (application is not notified)  RST: the peer host has crashed and rebooted. Socket’s pending error = ECONNRESET and socket is closed  No response: send 8 additional probes, 75 sec apart (totally, 11mim and 15sec). Listen the peer’s response. Still no response  ETIMEOUT and socket is closed Receives ICMP error, EHOSTUNREACH or …  To shorten probe period  Use TCP_KEEPALIVE option (Not all implementation support this option). But, this will affect all sockets on the host.  Or, implement your own heartbeat mechanism.

Ways to Detect Various TCP Condition

Default Operation of close  Any data remaining in the socket send buffer is sent. Close returns immediately without receiving ACK.  Client cannot know whether the data has been delivered correctly to the server !!!

Generic Socket Options(3)  SO_LINGER: linger when the socket is closed  Data type for option value  If l_onoff = 0, default close(). i.e. return immediately, but the remaining data is delivered to the peer  else  linger when the socket is closed  If l_linger==0, TCP aborts the connection. i.e. TCP discards any data still remaining in the socket send buffer and sends an RST to the peer.  else linger when the socket is closed. Any data still remaining in the socket send buffer is sent. But, if linger time expires, return EWOULDBLOCK and any remaining data is discarded.

Using shutdown to know that peer has received data

Generic Socket Options(4)  SO_OOBINLINE  OOB data will be placed in the normal input queue  SO_RCVBUF and SO_SNDBUF  Set or get socket send buffer size / socket receive buffer size  TCP:  advertise receive buffer(window) to the peer  sliding window mechanism(flow control)  buffer size  3 * MSS  UDP: typical send buffer size  9000, receive buffer size  40,000,  If data received > available receive buffer, datagram is discarded  Capacity of full-duplex pipe (bandwidth-delay product)  bandwidth * RTT (<= 64KB)  SO_RCVLOWAT, SO_SNDLOWAT: socket low water mark  data in socket receive buffer >= SO_RCVLOWAT  readable  available space in socket send buffer >= SO_SNDLOWAT  writable  SO_RCVLOWAT = 1, SO_SNDLOWAT = 2048 by default  SO_RCVTIMEO, SO_SNDTIMEO: socket time out for receiving and sending message

Generic Socket Options(6)  SO_REUSEADDR: reuse the established port  Allows a listening server to start and bind its well- known port even if previously established connections exist that use this port  Allows multiple instances of the same server to be started on the same port as long as each instance binds a different local IP address  hosting multiple HTTP servers using IP alias technique  Allows a single process to bind the same port to multiple socket as long as each bind specifies a different local IP address  Allows completely duplicate bindings when same IP address and port are already bound to another socket.  Used with multicasting to allow the same application to be run multiple times on the same host when the SO_REUSEPORT option is not supported

TCP Socket Options  TCP_KEEPALIVE: specifies the idle time in seconds for the connection before TCP starts sending keepalive probes  7200 sec (2 hours), default  Effective only when SO_KEEPALIVE socket option is enabled  TCP_MAXSEG: fetch or set MSS for TCP connection  TCP_NODELAY  e.g) rlogin, telnet  Nagle algorithm / delayed algorithm disabled  TCP’s Nagle algorithm  No small packet( < MSS ) will not be sent until the existing data is ACKed  TCP’s delayed ACK algorithm  piggyback: TCP sends an ACK after some small amount of time( 50 ~ 200msec)

Nagle Algorithm Enabled/Disabled  Nagle Algorithm Enabled  No small packet( < MSS ) will not be sent until the existing data is ACKed  Nagle Algorithm Disabled