~ubuntu-branches/ubuntu/oneiric/libclaw/oneiric

« back to all changes in this revision

Viewing changes to claw/impl/basic_socketbuf.tpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge
  • Date: 2010-12-23 20:55:14 UTC
  • mfrom: (4.2.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101223205514-s10m6ywla7s4ttqf
Tags: 1.6.1-3
UploadĀ inĀ sid

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
  CLAW is a free library without any particular aim but being useful to 
5
5
  anyone.
6
6
 
7
 
  Copyright (C) 2005-2008 Julien Jorge
 
7
  Copyright (C) 2005-2010 Julien Jorge
8
8
 
9
9
  This library is free software; you can redistribute it and/or
10
10
  modify it under the terms of the GNU Lesser General Public
36
36
/*----------------------------------------------------------------------------*/
37
37
/**
38
38
 * \brief Constructor.
 
39
 * \param read_limit Number of second to wait before considering nothing will
 
40
 *        come in the socket. Negative values mean infinity.
39
41
 * \post is_open() == false;
40
42
 */
41
43
template<typename CharT, typename Traits>
42
 
claw::net::basic_socketbuf<CharT, Traits>::basic_socketbuf()
43
 
  : m_input_buffer(NULL), m_input_buffer_size(0),
 
44
claw::net::basic_socketbuf<CharT, Traits>::basic_socketbuf( int read_limit )
 
45
  : m_read_limit(read_limit), m_input_buffer(NULL), m_input_buffer_size(0),
44
46
    m_output_buffer(NULL), m_output_buffer_size(0)
45
47
{
46
48
  create_buffers();
144
146
} // // basic_socketbuf::is_open()
145
147
 
146
148
/*----------------------------------------------------------------------------*/
 
149
/** 
 
150
 * \brief Set the number of second to wait before considering nothing will come
 
151
 *        in the socket.
 
152
 * \param read_limit The number of seconds. Negative values mean infinity.
 
153
 */
 
154
template<typename CharT, typename Traits>
 
155
void claw::net::basic_socketbuf<CharT, Traits>::set_read_time_limit
 
156
( int read_limit )
 
157
{
 
158
  m_read_limit = read_limit;
 
159
} // // basic_socketbuf::set_read_time_limit()
 
160
 
 
161
/*----------------------------------------------------------------------------*/
147
162
/**
148
163
 * \brief Write the buffered data in the socket.
149
164
 * \pre is_open()
181
196
typename claw::net::basic_socketbuf<CharT, Traits>::int_type
182
197
claw::net::basic_socketbuf<CharT, Traits>::underflow()
183
198
{
184
 
  CLAW_PRECOND( is_open() );
185
199
  CLAW_PRECOND( buffered() );
186
200
  CLAW_PRECOND( this->gptr() >= this->egptr() );
187
201
 
189
203
  ssize_t length = m_input_buffer_size * sizeof(char_type);
190
204
  int_type result = traits_type::eof();
191
205
 
192
 
  if ( socket_traits::select_read(m_descriptor) )
 
206
  if( !is_open() )
 
207
    return result;
 
208
 
 
209
  if ( socket_traits::select_read(m_descriptor, m_read_limit) )
193
210
    read_count = recv(m_descriptor, static_cast<char*>(m_input_buffer), length,
194
211
                      0);
195
212
  else