00001 /* 00002 Copyright (c) 2000, The JAP-Team 00003 All rights reserved. 00004 Redistribution and use in source and binary forms, with or without modification, 00005 are permitted provided that the following conditions are met: 00006 00007 - Redistributions of source code must retain the above copyright notice, 00008 this list of conditions and the following disclaimer. 00009 00010 - Redistributions in binary form must reproduce the above copyright notice, 00011 this list of conditions and the following disclaimer in the documentation and/or 00012 other materials provided with the distribution. 00013 00014 - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors 00015 may be used to endorse or promote products derived from this software without specific 00016 prior written permission. 00017 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 00020 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00021 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 00022 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00023 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00024 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00025 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00027 */ 00028 /* 00029 #include "StdAfx.h" 00030 #include "CAClientSocket.hpp" 00031 #include "CASocket.hpp" 00032 #include "CAUtil.hpp" 00033 #include "CASocketAddrINet.hpp" 00034 #ifdef HAVE_UNIX_DOMAIN_PROTOCOL 00035 #include "CASocketAddrUnix.hpp" 00036 #endif 00037 #include "CASingleSocketGroup.hpp" 00038 #include "CAMsg.hpp"; 00039 00040 00041 SINT32 CAClientSocket::receiveFullyT(UINT8* buff,UINT32 len,UINT32 msTimeOut) 00042 { 00043 SINT32 ret; 00044 UINT32 pos=0; 00045 UINT64 currentTime,endTime; 00046 bool bWasNonBlocking; 00047 00048 getcurrentTimeMillis(currentTime); 00049 set64(endTime,currentTime); 00050 add64(endTime,msTimeOut); 00051 00052 getSocket()->getNonBlocking(&bWasNonBlocking); 00053 if (!bWasNonBlocking) 00054 { 00055 getSocket()->setNonBlocking(true); 00056 } 00057 00058 CASingleSocketGroup oSG(false); 00059 oSG.add(*getSocket()); 00060 ret = 1; 00061 for(;;) 00062 { 00063 getcurrentTimeMillis(currentTime); 00064 if(!isLesser64(currentTime,endTime)) 00065 { 00066 if (!bWasNonBlocking) 00067 { 00068 getSocket()->setNonBlocking(false); 00069 } 00070 return E_TIMEDOUT; 00071 } 00072 msTimeOut=diff64(endTime,currentTime); 00073 00074 if(ret==1) 00075 { 00076 ret=receive(buff+pos,len); 00077 if(ret<=0) 00078 { 00079 if(ret==E_AGAIN) 00080 { 00081 //CAMsg::printMsg(LOG_DEBUG, "CAClientSocket:: Select\n"); 00082 ret=oSG.select(msTimeOut); 00083 //CAMsg::printMsg(LOG_DEBUG, "CAClientSocket:: After select\n"); 00084 continue; 00085 } 00086 else 00087 { 00088 if (!bWasNonBlocking) 00089 { 00090 getSocket()->setNonBlocking(false); 00091 } 00092 return E_UNKNOWN; 00093 } 00094 } 00095 pos+=ret; 00096 len-=ret; 00097 } 00098 else if(ret==E_TIMEDOUT) 00099 { 00100 if (!bWasNonBlocking) 00101 { 00102 getSocket()->setNonBlocking(false); 00103 } 00104 return E_TIMEDOUT; 00105 } 00106 00107 if(len==0) 00108 { 00109 if (!bWasNonBlocking) 00110 { 00111 getSocket()->setNonBlocking(false); 00112 } 00113 return E_SUCCESS; 00114 } 00115 } 00116 }*/
1.5.6