slide1
Download
Skip this Video
Download Presentation
I/O multiplexing , select and poll function

Loading in 2 Seconds...

play fullscreen
1 / 21

I/O multiplexing , select and poll function - PowerPoint PPT Presentation


  • 199 Views
  • Uploaded on

I/O multiplexing , select and poll function. INPUT / OUTPUT MODEL. SYNCHRONOUS I/O. ASYNCHRONOUS I/O. SYNCHRONOUS I/O A synchronous I/O causes the requesting process to be blocked until the operation Completes . ASYNCHRONOUS I/O

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'I/O multiplexing , select and poll function' - courtney


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide2
INPUT / OUTPUT MODEL

SYNCHRONOUS I/O

ASYNCHRONOUS I/O

SYNCHRONOUS I/O

A synchronous I/O causes the requestingprocess to be blocked until the operation Completes.

ASYNCHRONOUS I/O

A asynchronous I/O operation does not cause the requesting process to be blocked.

SYNCHRONOUS I/O

BLOCKING I/O

NON-BLOCKING I/O

I/O MULTIPLUXING

SIGNAL DRIVEN I/O

slide3
Blocked I/O

kernel

Application

recvfrom

No data gram

Data gram ready

Copy data gram

Process data gram

Copy complete

slide4
Non – blocking I/O

Application

kernel

recvfrom

No data gram

recvfrom

No data gram

No data gram

Recvfrom

recvfrom

Data gram ready

Copy datagram

Process data gram

Return OK

Copy complete

slide5
I/O MULTIPLEXING

Kernel

Application

System call

select

Data gram not ready

Return readable

Data gram ready

System call

recvfrom

Copy data gram

Return OK

Process datagram

Copy complete

slide6
Signal driven I/O

Application

kernel

Establish SIGIO

signalhandler

Data gram ready

Signal handler

recvfrom

Copy data gram

Process data gram

Return OK

Copy complete

slide7
Asynchronous I/O

kernel

Application

Aio_read

No data gram

Data gram ready

Copy data gram

Deliver signal

Process data gram

Copy complete

slide8
I/O multiplexing

This is implemented in the program using the select or the poll function. Now we will see the select function in detail.

SYNTAX:

#include

#include

int select(int maxfdp1,fd_set *readset, fd_set *writeset, fd_se t *exceptset , const struct timeval *timeout);

RETURNS:

+ve count of ready descripters

0    on time out

-1 on error

slide9
const struct timeval *timeout

This tells the kernel how long to wait for one of the specified descriptor to become ready.

Timeval a structure specifies the number of seconds and microseconds.

Struct timeval

{

long tv_sec;

long tv_usec;

};

*timeout may have three values

NULL -----return’s only when one of the specified descriptors is ready

0                 0 -----return’s immediately after checking , also called as polling.

particular time----returns when one of the specified descriptor is ready or after the specified time.

CONST:

Indicates that the value of the timeout will not return the number of seconds left if it has return before the stipulated time.

slide10
Int maxfdp1:

This gives the total number of descriptors the select function has to wait. Its value is maxfdp1+1.The decriptors0,1,2,……maxfd1-1 to be tested by the select command.

Fd_set:

This with the three cases i.e.,

Fd_set *readset

Fd_set *writeset

Fd_set *exceptset

Helps us to test the kernel for reading , writing , and exception.

slide11
conditions for a socket to be ready for reading and writing

condition

Exception ?

Readable ?

Writable ?

Data bytes in socket receive buffer> low-water mark

yes

Read half of the connection closed

yes

New connection ready for listening

yes

Data bytes in socket send buffer >=

low-water mark

yes

Write half of the connection closed

yes

Socket error is pending

yes

yes

TCP out – of – band data

yes

slide13
For ( ; ; )

{

select(maxfd1 , &rset , NULL , NULL , NULL);

If(FD_ISSET(sockfd , &rset))

{

If(readline(sockfd , recvline , MAXLINE)= = 0)

err_quit(“servet terminate”)

Fputs (recvline , stdout);

}

if(DF_ISSET(fileno(fp), &rset))

{

if(Fgets(sendline , MAXLINE , fp) = = NULL)

return;

write(sockfd , sendline ,strlen (sendline));

}

}

slide14
When select statement is used in the program

When connection is released at this point of time the all the data

grams at that Time in the network will be lost so we have to introduce a

Shout down function which Will terminate the connection in a proper manner

slide15
calling shut down to close the connection

data

data

S

E

R

V

E

R

FIN

C

L

I

E

N

T

FIN - ACC

data

data

FIN

FIN -ACC

slide16
Syntax for shutdownfunction

Int shutdown( int sockfd , int howto );

Returns 0 if OK

Returns -1 on error

It is found in the header file of

  the function of shutdown depends on the howto argument.

SHUT_RD The read half of the connection is closed.

SHUT_WR The write half the connection is closed.

SHUT_RDWR The both half of the connection are closed.

slide17
If(FD_ISSET(sockfd , &rset))

{

If(readline(sockfd , recvline , MAXLINE)= = 0)

{

If ( stdinof = = 1)

return;

else

err_quit(“servet terminate”) ;

}

Fputs (recvline , stdout);

}

if(DF_ISSET(fileno(fp), &rset))

{

if(Fgets(sendline , MAXLINE , fp) = = NULL)

{

stdinof = 1;

shutdown ( sockfd , SHUT_WR);

FD_CLR ( fileno(fp) , &rset);

Continue;

}

write(sockfd , sendline ,strlen (sendline));

}

slide18
pselect

Pselect function:

syntax:

#include

#include

#include

int pselect (int maxfdp1, fd_set *readset, fd_set

writeset, Fd_set *exceptset, const struct timespec *timeout, const sigset_t

*sigmask);

Returns:

count of ready descriptors if OK.

0 on time out.

-1 on error.

Timespec gives the time in seconds and nanoseconds.

Sigmask allows the program to disable the delivery of certain signals.

slide19
poll function

Syntax:

#include

int poll(struct pollfd *fdarray , unsigned long

nfds, int timeout);

Returns :

count of the ready descriptors of OK

0 on time out

-1 on error.

slide20
Arguments to poll:

The first argument is a pointer to the first element of an array of structures. Each element of the array is a pollfd structure.this specifies the conditions to be tested.

struct pollfd

{

int fd;

short event;

short revent;

};

Time out is:

INFTIM: wait for ever.

0 return immediately.

-1 error.

ad