#include <buffer.h>
Public Methods | |
| Buffer ( int checkSleep = 10000 ) | |
| Constructor (optional argument). More... | |
| ~Buffer () | |
| Deconstructor. More... | |
| void | write (packet* pak) |
| writes a packet into the buffer. More... | |
| packet* | read () |
| reads a packet from the buffer. More... | |
| bool | isEmpty () |
| checks if the buffer is empty. More... | |
Private Attributes | |
| int | checkSleep |
| the time it waits after realizing that the buffer is empty. More... | |
| pthread_mutex_t | buf_lock |
| The mutex lock to make the buffer threadsafe. More... | |
| pthread_mutex_t | buf_waitlock |
| not used/obsolete. More... | |
| queue<packet*> | intBuffer |
| internal queue. More... | |
Definition at line 14 of file buffer.h.
00014 {
00015 public:
00017
00020 Buffer ( int checkSleep = 10000 );
00022 ~Buffer ();
00023
00025
00028 void write (packet* pak);
00030
00033 packet* read ();
00034
00036
00039 bool isEmpty ();
00040
00041 private:
00042
00043 int checkSleep;
00044 pthread_mutex_t buf_lock;
00045 pthread_mutex_t buf_waitlock;
00046 queue<packet*> intBuffer;
00047 }
|
Constructor (optional argument).
| checkSleep | the time it waits to check the queue again (shall hopefully become obsolete very soon!) |
Definition at line 31 of file buffer.cpp.
00031 {
00032 checkSleep = cS;
00033 }
|
Deconstructor.
Definition at line 45 of file buffer.cpp.
00045 {
00046 while (!intBuffer.empty ()) intBuffer.pop ();
00047 }
|
checks if the buffer is empty.
Definition at line 111 of file buffer.cpp.
00112 {
00113 if (intBuffer.empty ())
00114 {
00115 usleep ( checkSleep );
00116 return true;
00117 }
00118 else
00119 {
00120 return false;
00121 };
00122 }
|
reads a packet from the buffer.
Definition at line 80 of file buffer.cpp.
00080 {
00081 packet* tmp;
00082
00083 pthread_mutex_lock ( &buf_lock );
00084
00085 if ( intBuffer.empty () )
00086 {
00087 tmp = 0;
00088 }
00089 else
00090 {
00091 tmp = intBuffer.front ();
00092 intBuffer.pop ();
00093 }
00094
00095 pthread_mutex_unlock ( &buf_lock );
00096
00097 return tmp;
00098 }
|
writes a packet into the buffer.
| pak | the packet |
Definition at line 60 of file buffer.cpp.
00061 {
00062 pthread_mutex_lock ( &buf_lock );
00063
00064 intBuffer.push (pak);
00065
00066 pthread_mutex_unlock ( &buf_lock );
00067 }
|
|
|
|
1.1.2 written by Dimitri van Heesch,
© 1997-2000