NCBI C++ ToolKit
ncbi_conn_reader_writer.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: ncbi_conn_reader_writer.cpp 66933 2015-04-01 21:51:06Z lavr $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Anton Lavrentiev
27  *
28  * File Description:
29  * Reader-writer implementations for connect library objects
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
35 
36 
38 
39 
41  size_t count,
42  void* del_ptr)
43 {
44  if (!m_Sock.IsOwned()) {
46  if (result != eRW_Success)
47  return result;
48  }
49  delete[] (CT_CHAR_TYPE*) del_ptr;
50  return eRW_Success;
51 }
52 
53 
55 {
56  static const STimeout kZero = {0, 0};
57  if (!m_Sock) {
58  return eRW_Error;
59  }
61  STimeout tmo;
62  if (tmp) {
63  tmo = *tmp;
64  tmp = &tmo;
65  }
66  if (m_Sock->SetTimeout(eIO_Read, &kZero) != eIO_Success) {
67  return eRW_Error;
68  }
69  EIO_Status status = m_Sock->Read(0, 1, count, eIO_ReadPeek);
71  return eRW_Error;
72  }
73  return status == eIO_Success || status == eIO_Timeout
75 }
76 
77 
79 {
80  switch (status) {
81  case eIO_Success:
82  return eRW_Success;
83  case eIO_Timeout:
84  return eRW_Timeout;
85  case eIO_Closed:
86  return eRW_Eof;
87  default:
88  break;
89  }
90  return eRW_Error;
91 }
92 
93 
static char tmp[3200]
Definition: utf8.c:42
bool IsOwned(void) const
Definition: ncbimisc.hpp:497
virtual ERW_Result PendingCount(size_t *count)
Via parameter "count" (which is guaranteed to be supplied non-NULL) return the number of bytes that a...
virtual ERW_Result Pushback(const void *buf, size_t count, void *del_ptr)
This method gets called by RStream buffer destructor to return buffered yet still unread (from the st...
ERW_Result x_Result(EIO_Status status)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
const STimeout * GetTimeout(EIO_Event event) const
Get timeout for I/O in the specified direction.
EIO_Status SetTimeout(EIO_Event event, const STimeout *timeout)
Set timeout for I/O in the specified direction.
EIO_Status Pushback(const void *buf, size_t size)
Push back data to socket (to be read out first).
EIO_Status Read(void *buf, size_t size, size_t *n_read=0, EIO_ReadMethod how=eIO_ReadPlain)
Read from socket.
ERW_Result
Result codes for I/O operations.
#define CT_CHAR_TYPE
Definition: ncbistre.hpp:729
@ eRW_Eof
End of data, should be considered permanent.
@ eRW_Error
Unrecoverable error, no retry possible.
@ eRW_Timeout
Timeout expired, try again later.
@ eRW_Success
Everything is okay, I/O completed.
EIO_Status
I/O status.
Definition: ncbi_core.h:132
@ eIO_Timeout
timeout expired before any I/O succeeded
Definition: ncbi_core.h:134
@ eIO_Success
everything is fine, no error occurred
Definition: ncbi_core.h:133
@ eIO_ReadPeek
do eIO_ReadPlain but leave data in input queue
Definition: ncbi_core.h:89
@ eIO_Read
read
Definition: ncbi_core.h:120
char * buf
#define count
Timeout structure.
Definition: ncbi_types.h:76
else result
Definition: token2.c:20
Modified on Fri Sep 20 14:58:08 2024 by modify_doxy.py rev. 669887