Peeking, Unix Sockets & Threads

  
 

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

(see chapter 23)
 

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()