Serial-Server Strategy - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Serial-Server Strategy

Description:

Initial client request serves to establish two way communication channel ... argv[1] = cougar. argv[2] = path1. argv[3] = path2. Client Send Path1 ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 11
Provided by: ralphh
Category:

less

Transcript and Presenter's Notes

Title: Serial-Server Strategy


1
Serial-Server Strategy
Server
Client
Client Request
Two-Way Communication
  • Two way channel is for additional interaction
    between client and server
  • Initial client request serves to establish two
    way communication channel
  • Communication channel is private not accessable
    to other processes
  • A busy server handling long-lived requests cannot
    use serial server strategy

2
Serial-Server Pseudocode
for () listen for client request
create private two-way communication channel
while (no error on communication channel)
read client request handle request and
respond to client close communication
channel
3
Parent-Server Strategy
Server
Client
Client Request
fork
Server Child
Two-Way Communication
  • Server resumes listing for more requests
  • Server forks a child to handle actual service
  • Similar to switchboard at hotel
  • Server can accept multiple client requests

4
Parent-Server Pseudocode
for () listen for client request
create a private two-way communication channel
fork a child to handle the request close the
communication channel clean up zombies
5
Thread-Server Strategy
Server Threads
Client
Client Request
Two-Way Communication
  • Low overhead alternative to parent-server
    strategy
  • Create thread to handle request instead of
    forking child threads have less overhead
  • Efficient if request is small or I/O intensive
  • Possible interference among multiple requests due
    to shared address space
  • For computationally intensive services,
    additional threads may reduce efficiency of or
    block the main server thread
  • Requires good kernel-level parallelism

6
Call
  • rcp cougar path1 path2
  • argv0 rcp
  • argv1 cougar
  • argv2 path1
  • argv3 path2

7
Client Send Path1
  • Client Bundle up path1 and send to server using
    network communications
  • write(commfd, argv2, sizeof(argv2))

8
Server Receive Path1
  • for ( ) if ((bytesread
    read(commfd, p_buf, BLKSIZE)) lt 0)
    read error break else if
    (bytesread 0) break
  • t_fd open(p_buf, O_RDONLY)

9
Server Read Path1 into s_buf and Send Contents to
Client
  • for ( ) if ((bytesread read(t_fd,
    s_buf, BLKSIZE)) lt 0) file read error
  • break else if (bytesread
    0) break else if (bytesread
    ! write(commfd, s_buf,
    (size_t)bytesread)) server write
    error break

10
Client Receive
  • p2fd open(argv3, O_WRONLY)
  • for ( )
  • if ((bytes_read read(commfd, c_buf, BLKSIZE))
    lt 0) client read error break else
    if (bytes_read 0) break else /
    allow for interruption of write by signal /
    for (bufp c_buf, bytes_to_write bytes_read
    bytes_to_write gt 0 bufp
    bytes_written, bytes_to_write - bytes_written)
    bytes_written write(p2fd, bufp,
    bytes_to_write) if ((bytes_written)
    -1 (errno ! EINTR)) client
    write error break
Write a Comment
User Comments (0)
About PowerShow.com