1 / 16

IEG4180 Tutorial 3

IEG4180 Tutorial 3. Shaoquan Zhang. Announcement. The deadline of the project 1 is extended to 11pm, 12/02/2011 Follow the requirement of the marking scheme. Outline. Stream socket programming I/O modes in Unix. Stream Socket Programming. Stream socket.

Download Presentation

IEG4180 Tutorial 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IEG4180 Tutorial 3 Shaoquan Zhang

  2. Announcement • The deadline of the project 1 is extended to 11pm, 12/02/2011 • Follow the requirement of the marking scheme

  3. Outline • Stream socket programming • I/O modes in Unix

  4. Stream Socket Programming • Stream socket Q: When is the three-way handshake happened? A: When the client calls the function connect(), the TCP connection is built before the accept(). The function accept() selects one from the established connection queue.

  5. TCP Connection Backlog • TCP Connection Queue • For a given listening socket, the kernel maintains two queues for client sockets: An incomplete connection queue: three-way handshake is not completed yet; A completed connection queue: three-way handshake is completed. • listen(socket s, int backlog) backlog: the maximum of the sum of two queue lengths • Problem: SYN attack

  6. Accept() • By default, when the completed queue is empty, the function will be blocked. • Methods: • poll() : accept() becomes non-blocking • select(): accept() is called only when the completed queue is not empty • Multithread • Message driven

  7. Message-driven Accept() SOCKET s=socket(); bind(); WSAAsyncSelect(s, m_hWnd, wMsg, FD_ACCEPT); //turn the socket s into a message-driven socket //m_hWnd: handle to window that will process the message //wMsg: message identifier; FD_ACCEPT: events to handle listen(s, 5);

  8. Message Flow

  9. WindowProc() HRESULT CNetProbeDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if(message==wMsg) { SOCKET s = (SOCKET)wParam; int event = WSAGETSELECTEVENT(lParam); switch(event){ case FD_ACCEPT: OnAccept(s); break; case FD_READ: OnRead(s); //receive data break; } } return CDialog::WindowProc(message, wParam, lParam); } message events to handle void CNetProbeDlg::OnAccept(SOCKET s) { SOCKET newsfd = accept(s,…); WSAAsyncSelect(newsfd, m_hWnd, wMsg, FD_READ); //turn the new socket into a message-driven one; handle the recv() }

  10. Add WindowProc() class review -> dialog class property overrides

  11. Unix I/O Modes • Blocking I/O • Non-blocking I/O • I/O multiplexing (select and poll) • Asynchronous I/O For a socket input operation, there are two steps: 1. wait data to arrive 2. copy data from kernel’s buffer to the process

  12. Blocking I/O Acknowledgement: following pictures come from UNIX Networking Programming

  13. Non-blocking I/O

  14. I/O Multiplexing

  15. Asynchronous I/O

  16. Backup Host A Host B SYN, seq=n SYN, seq=m ACK, seq=n+1 ACK, seq=m+1

More Related