SocketHelper.hpp 3.27 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/******************************************************************************
 *                      SocketHelper.hpp
 *
 * This file is part of the Castor project.
 * See http://castor.web.cern.ch/castor
 *
 * Copyright (C) 2003  CERN
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *
 *
22
 * @author Steven Murray Steven.Murray@cern.ch
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 *****************************************************************************/
 
#ifndef CASTOR_TAPE_AGGREGATOR_SOCKETHELPER_HPP
#define CASTOR_TAPE_AGGREGATOR_SOCKETHELPER_HPP 1

#include "castor/exception/PermissionDenied.hpp"

#include <iostream>
#include <stdint.h>


namespace castor {

  namespace io {
    // Forward declaration
38
    class AbstractTCPSocket;
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  }

namespace tape {
namespace aggregator {


  /**
   * Provides helper functions to work with sockets.
   */
  class SocketHelper {

  public:

    /**
     * Prints the string form of specified IP using the specified output
     * stream.
     *
56
57
     * @param os the output stream
     * @param ip the IP address in host byte order
58
59
60
61
62
63
64
     */
    static void printIp(std::ostream &os, const unsigned long ip) throw();

    /**
     * Prints a textual description of the specified socket to the specified
     * output stream.
     *
65
     * @param os the output stream to which the string is to be printed
66
     * @param the socket whose textual description is to be printed to the
67
     * stream
68
69
     */
    static void printSocketDescription(std::ostream &os,
70
      castor::io::AbstractTCPSocket &socket) throw();
71
72

    /**
73
74
     * Reads an unsigned 32-bit integer from the specified socket.
     *
75
76
77
78
79
     * @param the socket to be read from
     * @param netReadWriteTimeout the timeout to be used when performing
     * network reads and writes
     * @return the unsigned 32-bit integer
     */
80
    static uint32_t readUint32(castor::io::AbstractTCPSocket &socket,
81
82
83
84
85
86
87
88
89
90
91
      const int netReadWriteTimeout) throw (castor::exception::Exception);

    /**
     * Reads the specified number of bytes from the specified socket and writes
     * the result into the specified buffer.
     *
     * @param the socket to be read from
     * @param netReadWriteTimeout the timeout to be used when performing
     * network reads and writes
     * @param nbBytes the number of bytes to be read
     * @param buf the buffer into which the bytes will be written
92
     */
93
    static void readBytes(castor::io::AbstractTCPSocket &socket,
94
      const int netReadWriteTimeout, const int nbBytes, char *buf)
95
96
97
98
99
100
101
102
103
      throw (castor::exception::Exception);

  }; // class SocketHelper

} // namespace aggregator
} // namespace tape
} // namespace castor

#endif // CASTOR_TAPE_AGGREGATOR_SOCKETHELPER_HPP