Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / apps / JAWS / stress_testing / connection.cpp
blobdd96f3d306818ed8d964e6d9fcd55afe63d1c5db
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
10 // If not, append :80
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);
15 else {
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);
23 // Connect to server
25 ACE_SOCK_Connector con;
27 if(con.connect(stream_, server_addr) == -1) {
28 ACE_OS::perror("ACE_SOCK_Connector::connect");
29 return 1;
33 // tcp_nodelay processing.
35 // turn off weird ack things
36 if(tcp_nodelay) {
37 struct protoent *p = ACE_OS::getprotobyname ("tcp");
38 int one = 1;
40 if (p && stream_.set_option (p->p_proto,
41 TCP_NODELAY,
42 (char *)& one,
43 sizeof (one)))
45 ACE_OS::perror("tcp_nodelay");
46 return 1;
50 if(sockbufsiz)
51 if (stream_.set_option (SOL_SOCKET,
52 SO_RCVBUF,
53 (char *) &sockbufsiz,
54 sizeof sockbufsiz) == -1)
56 ACE_OS::perror("socket_queue_size");
57 return 1;
60 return 0;
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);
77 return 0;
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);
84 return 1;
87 int connection::close() {
88 stream_.close_reader();
89 stream_.close_writer();
90 stream_.close();
91 return 0;
94 connection::~connection() {
95 this->close();