IPClient.cc

Go to the documentation of this file.
00001 /*
00002  * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003  * downloading, copying, installing or using the software you agree to
00004  * this license. If you do not agree to this license, do not download,
00005  * install, copy or use the software.
00006  * 
00007  * Intel Open Source License 
00008  * 
00009  * Copyright (c) 2004 Intel Corporation. All rights reserved. 
00010  * 
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are
00013  * met:
00014  * 
00015  *   Redistributions of source code must retain the above copyright
00016  *   notice, this list of conditions and the following disclaimer.
00017  * 
00018  *   Redistributions in binary form must reproduce the above copyright
00019  *   notice, this list of conditions and the following disclaimer in the
00020  *   documentation and/or other materials provided with the distribution.
00021  * 
00022  *   Neither the name of the Intel Corporation nor the names of its
00023  *   contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *  
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
00030  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00031  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00032  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00033  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00034  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00035  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 
00039 
00040 #include <stdlib.h>
00041 #include <sys/poll.h>
00042 
00043 #include "IPClient.h"
00044 #include "util/Random.h"
00045 
00046 namespace oasys {
00047 
00048 IPClient::IPClient(int socktype, const char* logbase, Notifier* intr)
00049     : IOHandlerBase(intr), IPSocket(socktype, logbase)
00050 {}
00051 
00052 IPClient::IPClient(int socktype, int sock,
00053                    in_addr_t remote_addr, u_int16_t remote_port,
00054                    const char* logbase, Notifier* intr)
00055     : IOHandlerBase(intr), 
00056       IPSocket(socktype, sock, remote_addr, remote_port, logbase)
00057 {}
00058 
00059 IPClient::~IPClient() {}
00060 
00061 int
00062 IPClient::read(char* bp, size_t len)
00063 {
00064     // debugging hookto make sure that callers can handle short reads
00065     // #define TEST_SHORT_READ
00066 #ifdef TEST_SHORT_READ
00067     if (len > 64) {
00068         int rnd = Random::rand(len);
00069         ::logf("/test/shortread", LOG_DEBUG, "read(%d) -> read(%d)", len, rnd);
00070         len = rnd;
00071     }
00072 #endif
00073 
00074     int cc = IO::read(fd_, bp, len, get_notifier(), logpath_);
00075     monitor(IO::READV, 0); // XXX/bowei
00076 
00077     return cc;
00078 }
00079 
00080 int
00081 IPClient::readv(const struct iovec* iov, int iovcnt)
00082 {
00083     int cc = IO::readv(fd_, iov, iovcnt, get_notifier(), logpath_);
00084     monitor(IO::READV, 0); // XXX/bowei
00085 
00086     return cc;
00087 }
00088 
00089 int
00090 IPClient::write(const char* bp, size_t len)
00091 {
00092     int cc = IO::write(fd_, bp, len, get_notifier(), logpath_);
00093     monitor(IO::WRITEV, 0); // XXX/bowei
00094 
00095     return cc;
00096 }
00097 
00098 int
00099 IPClient::writev(const struct iovec* iov, int iovcnt)
00100 {
00101     int cc = IO::writev(fd_, iov, iovcnt, get_notifier(), logpath_);
00102     monitor(IO::WRITEV, 0); // XXX/bowei
00103 
00104     return cc;
00105 }
00106 
00107 int
00108 IPClient::readall(char* bp, size_t len)
00109 {
00110     int cc = IO::readall(fd_, bp, len, get_notifier(), logpath_);
00111     monitor(IO::READV, 0); // XXX/bowei
00112 
00113     return cc;
00114 }
00115 
00116 int
00117 IPClient::writeall(const char* bp, size_t len)
00118 {
00119     int cc = IO::writeall(fd_, bp, len, get_notifier(), logpath_);
00120     monitor(IO::WRITEV, 0); // XXX/bowei
00121 
00122     return cc;
00123 }
00124 
00125 int
00126 IPClient::readvall(const struct iovec* iov, int iovcnt)
00127 {
00128     int cc = IO::readvall(fd_, iov, iovcnt, get_notifier(), logpath_);
00129     monitor(IO::READV, 0); // XXX/bowei
00130 
00131     return cc;
00132 }
00133 
00134 int
00135 IPClient::writevall(const struct iovec* iov, int iovcnt)
00136 {
00137     int cc = IO::writevall(fd_, iov, iovcnt, get_notifier(), logpath_);
00138     monitor(IO::WRITEV, 0); // XXX/bowei
00139 
00140     return cc;
00141 }
00142 
00143 int
00144 IPClient::timeout_read(char* bp, size_t len, int timeout_ms)
00145 {
00146     int cc = IO::timeout_read(fd_, bp, len, timeout_ms, 
00147                             get_notifier(), logpath_);
00148     monitor(IO::READV, 0); // XXX/bowei
00149 
00150     return cc;
00151 }
00152 
00153 int
00154 IPClient::timeout_readv(const struct iovec* iov, int iovcnt, int timeout_ms)
00155 {
00156     int cc = IO::timeout_readv(fd_, iov, iovcnt, timeout_ms, 
00157                              get_notifier(), logpath_);
00158     monitor(IO::READV, 0); // XXX/bowei
00159 
00160     return cc;
00161 }
00162 
00163 int
00164 IPClient::timeout_readall(char* bp, size_t len, int timeout_ms)
00165 {
00166     int cc = IO::timeout_readall(fd_, bp, len, timeout_ms, 
00167                                get_notifier(), logpath_);
00168     monitor(IO::READV, 0); // XXX/bowei
00169 
00170     return cc;
00171 }
00172 
00173 int
00174 IPClient::timeout_readvall(const struct iovec* iov, int iovcnt, int timeout_ms)
00175 {
00176     int cc = IO::timeout_readvall(fd_, iov, iovcnt, timeout_ms, 
00177                                 get_notifier(), logpath_);
00178     monitor(IO::READV, 0); // XXX/bowei
00179 
00180     return cc;
00181 }
00182 
00183 int
00184 IPClient::timeout_write(const char* bp, size_t len, int timeout_ms)
00185 {
00186     int cc = IO::timeout_write(fd_, bp, len, timeout_ms, 
00187                                get_notifier(), logpath_);
00188     monitor(IO::WRITEV, 0); // XXX/bowei
00189 
00190     return cc;
00191 }
00192 
00193 int
00194 IPClient::timeout_writev(const struct iovec* iov, int iovcnt, int timeout_ms)
00195 {
00196     int cc = IO::timeout_writev(fd_, iov, iovcnt, timeout_ms, 
00197                                 get_notifier(), logpath_);
00198     monitor(IO::WRITEV, 0); // XXX/bowei
00199 
00200     return cc;
00201 }
00202 
00203 int
00204 IPClient::timeout_writeall(const char* bp, size_t len, int timeout_ms)
00205 {
00206     int cc = IO::timeout_writeall(fd_, bp, len, timeout_ms, 
00207                                   get_notifier(), logpath_);
00208     monitor(IO::WRITEV, 0); // XXX/bowei
00209 
00210     return cc;
00211 }
00212 
00213 int
00214 IPClient::timeout_writevall(const struct iovec* iov, int iovcnt, int timeout_ms)
00215 {
00216     int cc = IO::timeout_writevall(fd_, iov, iovcnt, timeout_ms, 
00217                                    get_notifier(), logpath_);
00218     monitor(IO::WRITEV, 0); // XXX/bowei
00219 
00220     return cc;
00221 }
00222 
00223 int
00224 IPClient::get_nonblocking(bool *nonblockingp)
00225 {
00226     int cc = IO::get_nonblocking(fd_, nonblockingp, logpath_);
00227     return cc;
00228 }
00229 
00230 int
00231 IPClient::set_nonblocking(bool nonblocking)
00232 {
00233     int cc = IO::set_nonblocking(fd_, nonblocking, logpath_);
00234     return cc;
00235 }
00236 
00237 } // namespace oasys

Generated on Fri Dec 22 14:47:59 2006 for DTN Reference Implementation by  doxygen 1.5.1