libsocket 1.5
|
00001 /* 00002 ** socket.hxx 00003 ** Login : Julien Lemoine <speedblue@happycoders.org> 00004 ** Started on Tue Jun 1 22:45:16 2004 Julien Lemoine 00005 ** $Id: socket.hxx,v 1.2 2004/11/14 19:37:46 speedblue Exp $ 00006 ** 00007 ** Copyright (C) 2004 Julien Lemoine 00008 ** This program is free software; you can redistribute it and/or modify 00009 ** it under the terms of the GNU Lesser General Public License as published by 00010 ** the Free Software Foundation; either version 2 of the License, or 00011 ** (at your option) any later version. 00012 ** 00013 ** This program is distributed in the hope that it will be useful, 00014 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 ** GNU Lesser General Public License for more details. 00017 ** 00018 ** You should have received a copy of the GNU Lesser General Public License 00019 ** along with this program; if not, write to the Free Software 00020 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 #ifndef SOCKET_HXX_ 00024 # define SOCKET_HXX_ 00025 00026 namespace Network 00027 { 00028 inline bool Socket::_check_answer(int res, std::string &str) 00029 { 00030 if (res <= 0) 00031 { 00032 if (!_buffer.size()) // No more data... 00033 throw ConnectionClosed("Connection Closed", HERE); 00034 else 00035 { 00036 str += _buffer; 00037 _buffer = ""; 00038 _state_timeout = 0; 00039 return true; 00040 } 00041 } 00042 return false; 00043 } 00044 00045 inline bool Socket::_update_buffer(std::pair<int, int> &delim, 00046 int &i, std::string &str) 00047 { 00048 delim = _find_delim(_buffer, 0); 00049 i = delim.first; 00050 while (!_empty_lines && !i) 00051 { 00052 // remove delimiter in front of buffer 00053 _buffer = _buffer.substr(delim.second, _buffer.size() - delim.second); 00054 delim = _find_delim(_buffer, 0); 00055 i = delim.first; 00056 } 00057 if ((i > 0 || _empty_lines) && ((unsigned int)i < _buffer.size())) 00058 { 00059 str = _buffer.substr(0, i); 00060 _buffer = _buffer.substr(i + delim.second, 00061 _buffer.size() - i - delim.second); 00062 return true; 00063 } 00064 else 00065 return false; 00066 } 00067 } 00068 00069 #endif /* !SOCKET_HXX_ */