1 #include "connection.h"
3 // Make the connection to the WEB server
5 int connection::connect(char *hostname_opt_port
, int tcp_nodelay
, int sockbufsiz
) {
6 if(!hostname_opt_port
) return 1;
8 char *hostname_with_port
;
9 // Check to see if portnumber is specified in the hostnameport
11 if(!ACE_OS::strchr(hostname_opt_port
,':')) {
12 hostname_with_port
= new char[ACE_OS::strlen(hostname_opt_port
) + 3];
13 ACE_OS::sprintf(hostname_with_port
, "%s:%d", hostname_opt_port
, 80);
16 hostname_with_port
= hostname_opt_port
;
19 // Beyond this point, hostname_with_port is of the form hostname:port
21 ACE_INET_Addr
server_addr(hostname_with_port
);
25 ACE_SOCK_Connector con
;
27 if(con
.connect(stream_
, server_addr
) == -1) {
28 ACE_OS::perror("ACE_SOCK_Connector::connect");
33 // tcp_nodelay processing.
35 // turn off weird ack things
37 struct protoent
*p
= ACE_OS::getprotobyname ("tcp");
40 if (p
&& stream_
.set_option (p
->p_proto
,
45 ACE_OS::perror("tcp_nodelay");
51 if (stream_
.set_option (SOL_SOCKET
,
54 sizeof sockbufsiz
) == -1)
56 ACE_OS::perror("socket_queue_size");
63 int connection::read(void *buffer
, size_t maxlen
, unsigned int timeout_seconds
) {
64 ACE_UNUSED_ARG (timeout_seconds
);
65 return stream_
.recv(buffer
, maxlen
);
68 int connection::write(const void *buffer
, size_t maxlen
, unsigned int timeout_seconds
) {
69 ACE_UNUSED_ARG (timeout_seconds
);
70 return stream_
.send(buffer
, maxlen
);
73 int connection::write_n(const void *buffer
, size_t len
, unsigned int timeout_seconds
) {
74 ACE_UNUSED_ARG (timeout_seconds
);
75 if(stream_
.send_n(buffer
, len
) == -1)
76 ACE_ERROR_RETURN((LM_ERROR
, "Write failed for %s", buffer
),1);
80 int connection::read_n(void *buffer
, size_t maxlen
, unsigned int timeout_seconds
) {
81 ACE_UNUSED_ARG (timeout_seconds
);
82 if(stream_
.recv_n(buffer
, maxlen
) == -1)
83 ACE_ERROR_RETURN((LM_ERROR
, "Read failed.."),1);
87 int connection::close() {
88 stream_
.close_reader();
89 stream_
.close_writer();
94 connection::~connection() {