91
gearman_connection_st::gearman_connection_st(gearman_universal_st &universal_arg) :
91
gearman_connection_st::gearman_connection_st(gearman_universal_st &universal_arg, const char* host_, const char* service_):
92
92
state(GEARMAN_CON_UNIVERSAL_ADDRINFO),
93
93
send_state(GEARMAN_CON_SEND_STATE_NONE),
94
94
recv_state(GEARMAN_CON_RECV_UNIVERSAL_NONE),
125
127
send_buffer_ptr= send_buffer;
126
128
recv_buffer_ptr= recv_buffer;
132
* Initialize a connection structure. Always check the return value even if
133
* passing in a pre-allocated structure. Some other initialization may have
136
static gearman_connection_st *__connection_create(gearman_universal_st &universal)
131
gearman_connection_st *gearman_connection_create(gearman_universal_st& universal,
132
const char *host_, const char* service_)
138
gearman_connection_st *connection= new (std::nothrow) gearman_connection_st(universal);
139
if (connection == NULL)
134
gearman_connection_st *connection= new (std::nothrow) gearman_connection_st(universal, host_, service_);
137
if (gearman_failed(connection->lookup()))
141
145
gearman_perror(universal, errno, "Failed at new() gearman_connection_st new");
147
151
gearman_connection_st *gearman_connection_create(gearman_universal_st& universal,
148
const char *host, const char* service_)
150
gearman_connection_st *connection= __connection_create(universal);
153
connection->set_host(host, (const char*)service_);
155
if (gearman_failed(connection->lookup()))
165
gearman_connection_st *gearman_connection_create(gearman_universal_st& universal,
166
const char *host, const in_port_t& port)
168
gearman_connection_st *connection= __connection_create(universal);
171
connection->set_host(host, port);
173
if (gearman_failed(connection->lookup()))
152
const char *host, const in_port_t& port_)
154
const char *service_ptr= NULL;
155
char service[GEARMAN_NI_MAXSERV];
159
service_ptr= GEARMAN_DEFAULT_TCP_PORT_STRING;
163
snprintf(service, sizeof(service), "%hu", uint16_t(port_));
164
service[GEARMAN_NI_MAXSERV -1]= 0;
166
service_ptr= service;
169
return gearman_connection_create(universal, host, service_ptr);
183
172
gearman_connection_st *gearman_connection_copy(gearman_universal_st& universal,
184
173
const gearman_connection_st& from)
186
gearman_connection_st *connection= __connection_create(universal);
175
gearman_connection_st *connection= new (std::nothrow) gearman_connection_st(universal, from.host(), from.service());
190
178
connection->options.ready= from.options.ready;
194
182
strcpy(connection->_host, from._host);
195
183
strcpy(connection->_service, from._service);
187
gearman_perror(universal, errno, "Failed at new() gearman_connection_st new");
198
190
return connection;
252
244
snprintf(_service, sizeof(_service), "%hu", uint16_t(port_));
253
_service[GEARMAN_NI_MAXSERV - 1]= 0;
245
_service[GEARMAN_NI_MAXSERV -1]= 0;
255
247
set_host(host_, _service);
267
259
host_= GEARMAN_DEFAULT_TCP_HOST;
269
261
strncpy(_host, host_, GEARMAN_NI_MAXHOST);
270
_host[GEARMAN_NI_MAXHOST - 1]= 0;
262
_host[GEARMAN_NI_MAXHOST -1]= 0;
272
if (service_ != _service)
264
if (service_ and service_[0])
276
size_t string_len= strlen(service_);
279
service_= GEARMAN_DEFAULT_TCP_PORT_STRING;
284
service_= GEARMAN_DEFAULT_TCP_PORT_STRING;
286
strncpy(_service, service_, GEARMAN_NI_MAXSERV);
287
_service[GEARMAN_NI_MAXSERV - 1]= 0;
268
service_= GEARMAN_DEFAULT_TCP_PORT_STRING;
270
strncpy(_service, service_, GEARMAN_NI_MAXSERV);
271
_service[GEARMAN_NI_MAXSERV -1]= 0;