Peeking, Unix Sockets & Threads

 

 

 

Ø   Peeking at received data

Ø   Unix domain sockets

ü Stream

ü Datagram

Ø   Threads

ü Functions

ü Simple Example

ü Synchronization



 

Ø   Peeking at received data:

 

ü      PeekServer.c  & 

ü      PeekClient.c


  Peek:
            cc = recv(fd, buf, sizeof buf, MSG_PEEK);

  Read:

            cc = recv(fd, buf, sizeof buf,0);

 

 



Ø   Unix domain sockets:

 

ü Stream

 

à      unixstrcli01.c  &

à      unixstrserv01c

 

The client and server communicate via the common file:

 

#define UNIXSTR_PATH    "/tmp/unix.str"

 

ü Datagram

 

à      unixdgcli01.c  &

à      unixdgserv01.c

 

The client and server communicate via the common file:

 

#define UNIXDG_PATH      "/tmp/unix.dg"

 



 

 

Ø   Threads


 

ü Functions:

à      pthread_create  (ThreadID, Priority, Starting Fun, Fun Args)

à      pthread_join    // similar to waitpid

à      pthread_self     // similar to getpid

à      pthread_detach  // not joinable

à      pthread_exit     // terminate a thread;

à      // calling exit() kills ALL threads.
 
 

ü Simple Exampls:

à   tcpcli01.c uses (strclithread.c)  & 

à   tcpserv01.c

 

 

ü Synchronization:

à   non-synch example:   example01.c

 

use: % script file
        % example01
        % look at file to see the problem

 

 

à   synchronized example:   example02.c

 

           It uses:

 

Pthread_mutex_lock()

 

       { Critical Section}

 

Pthread_mutex_unlock()