~clint-fewbar/ubuntu/precise/gearmand/drop-unneeded-patches

« back to all changes in this revision

Viewing changes to libgearman/connection.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2009-08-11 10:06:22 UTC
  • mto: (1.2.3 upstream) (6.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20090811100622-6ig4iknanc73olum
ImportĀ upstreamĀ versionĀ 0.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2
 
 * 
3
 
 *  Gearmand client and server library.
4
 
 *
5
 
 *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
6
 
 *  Copyright (C) 2008 Brian Aker, Eric Day
7
 
 *  All rights reserved.
8
 
 *
9
 
 *  Redistribution and use in source and binary forms, with or without
10
 
 *  modification, are permitted provided that the following conditions are
11
 
 *  met:
12
 
 *
13
 
 *      * Redistributions of source code must retain the above copyright
14
 
 *  notice, this list of conditions and the following disclaimer.
15
 
 *
16
 
 *      * Redistributions in binary form must reproduce the above
17
 
 *  copyright notice, this list of conditions and the following disclaimer
18
 
 *  in the documentation and/or other materials provided with the
19
 
 *  distribution.
20
 
 *
21
 
 *      * The names of its contributors may not be used to endorse or
22
 
 *  promote products derived from this software without specific prior
23
 
 *  written permission.
24
 
 *
25
 
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
 
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
 
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
 
 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
 
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
 
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
 
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
 
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
 
 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
 
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
 
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
 
 *
37
 
 */
38
 
 
39
 
#pragma once
40
 
 
41
 
#include <libgearman-1.0/connection.h>
42
 
 
43
 
struct gearman_connection_st
44
 
{
45
 
  struct {
46
 
    bool ready;
47
 
    bool packet_in_use;
48
 
  } options;
49
 
  enum gearman_con_universal_t state;
50
 
  enum gearman_con_send_t send_state;
51
 
  enum gearman_con_recv_t recv_state;
52
 
  in_port_t port;
53
 
  short events;
54
 
  short revents;
55
 
  int fd;
56
 
  int cached_errno;
57
 
  uint32_t created_id;
58
 
  uint32_t created_id_next;
59
 
  size_t send_buffer_size;
60
 
  size_t send_data_size;
61
 
  size_t send_data_offset;
62
 
  size_t recv_buffer_size;
63
 
  size_t recv_data_size;
64
 
  size_t recv_data_offset;
65
 
  gearman_universal_st &universal;
66
 
  gearman_connection_st *next;
67
 
  gearman_connection_st *prev;
68
 
  void *context;
69
 
  struct addrinfo *addrinfo;
70
 
  struct addrinfo *addrinfo_next;
71
 
  char *send_buffer_ptr;
72
 
  gearman_packet_st *recv_packet;
73
 
  char *recv_buffer_ptr;
74
 
  gearman_packet_st _packet;
75
 
  char host[GEARMAN_NI_MAXHOST];
76
 
  char send_buffer[GEARMAN_SEND_BUFFER_SIZE];
77
 
  char recv_buffer[GEARMAN_RECV_BUFFER_SIZE];
78
 
 
79
 
  void free_private_packet();
80
 
 
81
 
  gearman_connection_st(gearman_universal_st &universal_arg,
82
 
                        gearman_connection_options_t *options);
83
 
 
84
 
  ~gearman_connection_st();
85
 
 
86
 
  void set_host( const char *host, const in_port_t port);
87
 
 
88
 
  gearman_return_t send_packet(const gearman_packet_st&, const bool flush_buffer);
89
 
  size_t send_and_flush(const void *data, size_t data_size, gearman_return_t *ret_ptr);
90
 
 
91
 
  gearman_return_t flush();
92
 
  void close_socket();
93
 
 
94
 
  // Receive packet from a connection.
95
 
  gearman_packet_st *receiving(gearman_packet_st&,
96
 
                               gearman_return_t& , const bool recv_data);
97
 
 
98
 
  // Receive packet data from a connection.
99
 
  size_t receiving(void *data, size_t data_size, gearman_return_t&);
100
 
 
101
 
  // Set events to be watched for a connection.
102
 
  void set_events(short events);
103
 
 
104
 
 // Set events that are ready for a connection. This is used with the
105
 
 // external event callbacks.
106
 
  void set_revents(short revents);
107
 
 
108
 
  void reset_addrinfo();
109
 
 
110
 
  gearman_return_t lookup();
111
 
 
112
 
private:
113
 
  size_t recv_socket(void *data, size_t data_size, gearman_return_t&);
114
 
  gearman_return_t connect_poll();
115
 
};
116
 
 
117
 
/**
118
 
 * Initialize a connection structure. Always check the return value even if
119
 
 * passing in a pre-allocated structure. Some other initialization may have
120
 
 * failed.
121
 
 */
122
 
 
123
 
GEARMAN_LOCAL
124
 
gearman_connection_st *gearman_connection_create(gearman_universal_st &universal,
125
 
                                                 gearman_connection_options_t *options);
126
 
 
127
 
GEARMAN_LOCAL
128
 
gearman_connection_st *gearman_connection_copy(gearman_universal_st& universal,
129
 
                                               const gearman_connection_st& from);
130
 
 
131
 
/**
132
 
 * Create a connection structure with the given host and port.
133
 
 *
134
 
 * @param[in] gearman Structure previously initialized with gearman_create() or
135
 
 *  gearman_clone().
136
 
 * @param[in] connection Caller allocated structure, or NULL to allocate one.
137
 
 * @param[in] host Host or IP address to connect to.
138
 
 * @param[in] port Port to connect to.
139
 
 * @return On success, a pointer to the (possibly allocated) structure. On
140
 
 *  failure this will be NULL.
141
 
 */
142
 
GEARMAN_LOCAL
143
 
gearman_connection_st *gearman_connection_create_args(gearman_universal_st &universal,
144
 
                                                      const char *host, in_port_t port);