00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include <vpr/vprConfig.h>
00043
00044 #include <vpr/IO/BlockIO.h>
00045
00046
00047 namespace vpr
00048 {
00049
00050 bool BlockIO::isReadBlocked(const vpr::Interval& timeout)
00051 {
00052 bool is_blocked;
00053 vpr::Selector selector;
00054 vpr::IOSys::Handle handle;
00055 vpr::Uint16 num_events;
00056 vpr::ReturnStatus status;
00057
00058 handle = getHandle();
00059 selector.addHandle(handle);
00060 selector.setIn(handle, vpr::Selector::Read);
00061
00062
00063 status = selector.select(num_events, timeout);
00064
00065 if ( num_events == 1 )
00066 {
00067 is_blocked = false;
00068 }
00069 else
00070 {
00071 is_blocked = true;
00072 }
00073
00074 return is_blocked;
00075 }
00076
00077 bool BlockIO::isWriteBlocked(const vpr::Interval& timeout)
00078 {
00079 bool is_blocked;
00080 vpr::Selector selector;
00081 vpr::IOSys::Handle handle;
00082 vpr::Uint16 num_events;
00083 vpr::ReturnStatus status;
00084
00085 handle = getHandle();
00086 selector.addHandle(handle);
00087 selector.setIn(handle, vpr::Selector::Write);
00088
00089
00090 status = selector.select(num_events, timeout);
00091
00092 if ( num_events == 1 )
00093 {
00094 is_blocked = false;
00095 }
00096 else
00097 {
00098 is_blocked = true;
00099 }
00100
00101 return is_blocked;
00102 }
00103
00104 BlockIO::BlockIO()
00105 : mOpen(false)
00106 , mBlocking(true)
00107 , mStatsStrategy(NULL)
00108 {
00109 ;
00110 }
00111
00112 BlockIO::BlockIO(const std::string& name)
00113 : mName(name)
00114 , mOpen(false)
00115 , mBlocking(true)
00116 , mStatsStrategy(NULL)
00117 {
00118 ;
00119 }
00120
00121 BlockIO::BlockIO(const BlockIO& other)
00122 : mName(other.mName)
00123 , mOpen(other.mOpen)
00124 , mBlocking(other.mBlocking)
00125 , mStatsStrategy(NULL)
00126 {
00127 ;
00128 }
00129
00130 BlockIO::~BlockIO()
00131 {
00132 ;
00133 }
00134
00135 vpr::ReturnStatus BlockIO::read_s(void* buffer, const vpr::Uint32 length,
00136 vpr::Uint32& bytesRead,
00137 const vpr::Interval timeout)
00138 {
00139 vpr::ReturnStatus status;
00140
00141 if(mStatsStrategy != NULL)
00142 {
00143 mStatsStrategy->read_s(status, buffer, length, bytesRead, timeout);
00144 }
00145 else
00146 {
00147 status = read_i(buffer, length, bytesRead, timeout);
00148 }
00149
00150 return status;
00151 }
00152
00153 vpr::ReturnStatus BlockIO::readn_s(void* buffer, const vpr::Uint32 length,
00154 vpr::Uint32& bytesRead,
00155 const vpr::Interval timeout)
00156 {
00157 vpr::ReturnStatus status;
00158
00159 if(mStatsStrategy != NULL)
00160 {
00161 mStatsStrategy->readn_s(status, buffer, length, bytesRead, timeout);
00162 }
00163 else
00164 {
00165 status = readn_i(buffer, length, bytesRead, timeout);
00166 }
00167
00168 return status;
00169 }
00170
00171 vpr::ReturnStatus BlockIO::write_s(const void* buffer,
00172 const vpr::Uint32 length,
00173 vpr::Uint32& bytesWritten,
00174 const vpr::Interval timeout)
00175 {
00176 vpr::ReturnStatus status;
00177
00178 if(mStatsStrategy != NULL)
00179 {
00180 mStatsStrategy->write_s(status, buffer, length, bytesWritten,
00181 timeout);
00182 }
00183 else
00184 {
00185 status = write_i(buffer, length, bytesWritten, timeout);
00186 }
00187
00188 return status;
00189 }
00190
00191 }