IPClient.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 
00019 #include <stdlib.h>
00020 #include <sys/poll.h>
00021 
00022 #include "IPClient.h"
00023 #include "util/Random.h"
00024 
00025 namespace oasys {
00026 
00027 IPClient::IPClient(int socktype, const char* logbase, Notifier* intr)
00028     : IOHandlerBase(intr), IPSocket(socktype, logbase)
00029 {}
00030 
00031 IPClient::IPClient(int socktype, int sock,
00032                    in_addr_t remote_addr, u_int16_t remote_port,
00033                    const char* logbase, Notifier* intr)
00034     : IOHandlerBase(intr), 
00035       IPSocket(socktype, sock, remote_addr, remote_port, logbase)
00036 {}
00037 
00038 IPClient::~IPClient() {}
00039 
00040 int
00041 IPClient::read(char* bp, size_t len)
00042 {
00043     // debugging hookto make sure that callers can handle short reads
00044     // #define TEST_SHORT_READ
00045 #ifdef TEST_SHORT_READ
00046     if (len > 64) {
00047         int rnd = Random::rand(len);
00048         ::logf("/test/shortread", LOG_DEBUG, "read(%d) -> read(%d)", len, rnd);
00049         len = rnd;
00050     }
00051 #endif
00052 
00053     int cc = IO::read(fd_, bp, len, get_notifier(), logpath_);
00054     monitor(IO::READV, 0); // XXX/bowei
00055 
00056     return cc;
00057 }
00058 
00059 int
00060 IPClient::readv(const struct iovec* iov, int iovcnt)
00061 {
00062     int cc = IO::readv(fd_, iov, iovcnt, get_notifier(), logpath_);
00063     monitor(IO::READV, 0); // XXX/bowei
00064 
00065     return cc;
00066 }
00067 
00068 int
00069 IPClient::write(const char* bp, size_t len)
00070 {
00071     int cc = IO::write(fd_, bp, len, get_notifier(), logpath_);
00072     monitor(IO::WRITEV, 0); // XXX/bowei
00073 
00074     return cc;
00075 }
00076 
00077 int
00078 IPClient::writev(const struct iovec* iov, int iovcnt)
00079 {
00080     int cc = IO::writev(fd_, iov, iovcnt, get_notifier(), logpath_);
00081     monitor(IO::WRITEV, 0); // XXX/bowei
00082 
00083     return cc;
00084 }
00085 
00086 int
00087 IPClient::readall(char* bp, size_t len)
00088 {
00089     int cc = IO::readall(fd_, bp, len, get_notifier(), logpath_);
00090     monitor(IO::READV, 0); // XXX/bowei
00091 
00092     return cc;
00093 }
00094 
00095 int
00096 IPClient::writeall(const char* bp, size_t len)
00097 {
00098     int cc = IO::writeall(fd_, bp, len, get_notifier(), logpath_);
00099     monitor(IO::WRITEV, 0); // XXX/bowei
00100 
00101     return cc;
00102 }
00103 
00104 int
00105 IPClient::readvall(const struct iovec* iov, int iovcnt)
00106 {
00107     int cc = IO::readvall(fd_, iov, iovcnt, get_notifier(), logpath_);
00108     monitor(IO::READV, 0); // XXX/bowei
00109 
00110     return cc;
00111 }
00112 
00113 int
00114 IPClient::writevall(const struct iovec* iov, int iovcnt)
00115 {
00116     int cc = IO::writevall(fd_, iov, iovcnt, get_notifier(), logpath_);
00117     monitor(IO::WRITEV, 0); // XXX/bowei
00118 
00119     return cc;
00120 }
00121 
00122 int
00123 IPClient::timeout_read(char* bp, size_t len, int timeout_ms)
00124 {
00125     int cc = IO::timeout_read(fd_, bp, len, timeout_ms, 
00126                             get_notifier(), logpath_);
00127     monitor(IO::READV, 0); // XXX/bowei
00128 
00129     return cc;
00130 }
00131 
00132 int
00133 IPClient::timeout_readv(const struct iovec* iov, int iovcnt, int timeout_ms)
00134 {
00135     int cc = IO::timeout_readv(fd_, iov, iovcnt, timeout_ms, 
00136                              get_notifier(), logpath_);
00137     monitor(IO::READV, 0); // XXX/bowei
00138 
00139     return cc;
00140 }
00141 
00142 int
00143 IPClient::timeout_readall(char* bp, size_t len, int timeout_ms)
00144 {
00145     int cc = IO::timeout_readall(fd_, bp, len, timeout_ms, 
00146                                get_notifier(), logpath_);
00147     monitor(IO::READV, 0); // XXX/bowei
00148 
00149     return cc;
00150 }
00151 
00152 int
00153 IPClient::timeout_readvall(const struct iovec* iov, int iovcnt, int timeout_ms)
00154 {
00155     int cc = IO::timeout_readvall(fd_, iov, iovcnt, timeout_ms, 
00156                                 get_notifier(), logpath_);
00157     monitor(IO::READV, 0); // XXX/bowei
00158 
00159     return cc;
00160 }
00161 
00162 int
00163 IPClient::timeout_write(const char* bp, size_t len, int timeout_ms)
00164 {
00165     int cc = IO::timeout_write(fd_, bp, len, timeout_ms, 
00166                                get_notifier(), logpath_);
00167     monitor(IO::WRITEV, 0); // XXX/bowei
00168 
00169     return cc;
00170 }
00171 
00172 int
00173 IPClient::timeout_writev(const struct iovec* iov, int iovcnt, int timeout_ms)
00174 {
00175     int cc = IO::timeout_writev(fd_, iov, iovcnt, timeout_ms, 
00176                                 get_notifier(), logpath_);
00177     monitor(IO::WRITEV, 0); // XXX/bowei
00178 
00179     return cc;
00180 }
00181 
00182 int
00183 IPClient::timeout_writeall(const char* bp, size_t len, int timeout_ms)
00184 {
00185     int cc = IO::timeout_writeall(fd_, bp, len, timeout_ms, 
00186                                   get_notifier(), logpath_);
00187     monitor(IO::WRITEV, 0); // XXX/bowei
00188 
00189     return cc;
00190 }
00191 
00192 int
00193 IPClient::timeout_writevall(const struct iovec* iov, int iovcnt, int timeout_ms)
00194 {
00195     int cc = IO::timeout_writevall(fd_, iov, iovcnt, timeout_ms, 
00196                                    get_notifier(), logpath_);
00197     monitor(IO::WRITEV, 0); // XXX/bowei
00198 
00199     return cc;
00200 }
00201 
00202 int
00203 IPClient::get_nonblocking(bool *nonblockingp)
00204 {
00205     int cc = IO::get_nonblocking(fd_, nonblockingp, logpath_);
00206     return cc;
00207 }
00208 
00209 int
00210 IPClient::set_nonblocking(bool nonblocking)
00211 {
00212     int cc = IO::set_nonblocking(fd_, nonblocking, logpath_);
00213     return cc;
00214 }
00215 
00216 } // namespace oasys

Generated on Sat Sep 8 08:36:17 2007 for DTN Reference Implementation by  doxygen 1.5.3