aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/llmessage/llares.cpp17
-rw-r--r--linden/indra/llmessage/llcurl.cpp2
-rw-r--r--linden/indra/llmessage/lliohttpserver.cpp10
-rw-r--r--linden/indra/llmessage/lliohttpserver.h2
-rw-r--r--linden/indra/llmessage/lliosocket.cpp99
-rw-r--r--linden/indra/llmessage/lliosocket.h33
-rw-r--r--linden/indra/llmessage/llmail.cpp17
-rw-r--r--linden/indra/llmessage/llmail.h4
-rw-r--r--linden/indra/llmessage/llpumpio.cpp74
-rw-r--r--linden/indra/llmessage/llpumpio.h31
-rw-r--r--linden/indra/llmessage/llurlrequest.cpp25
-rw-r--r--linden/indra/llmessage/message.cpp17
12 files changed, 121 insertions, 210 deletions
diff --git a/linden/indra/llmessage/llares.cpp b/linden/indra/llmessage/llares.cpp
index fe37fe8..5a6794e 100644
--- a/linden/indra/llmessage/llares.cpp
+++ b/linden/indra/llmessage/llares.cpp
@@ -43,6 +43,7 @@
43 43
44#include "llapr.h" 44#include "llapr.h"
45#include "llares.h" 45#include "llares.h"
46#include "llscopedvolatileaprpool.h"
46 47
47#if defined(LL_WINDOWS) 48#if defined(LL_WINDOWS)
48# define ns_c_in 1 49# define ns_c_in 1
@@ -463,11 +464,6 @@ void LLAres::search(const std::string &query, LLResType type,
463 464
464bool LLAres::process(U64 timeout) 465bool LLAres::process(U64 timeout)
465{ 466{
466 if (!gAPRPoolp)
467 {
468 ll_init_apr();
469 }
470
471 int socks[ARES_GETSOCK_MAXNUM]; 467 int socks[ARES_GETSOCK_MAXNUM];
472 apr_pollfd_t aprFds[ARES_GETSOCK_MAXNUM]; 468 apr_pollfd_t aprFds[ARES_GETSOCK_MAXNUM];
473 apr_int32_t nsds = 0; 469 apr_int32_t nsds = 0;
@@ -481,10 +477,7 @@ bool LLAres::process(U64 timeout)
481 return nsds > 0; 477 return nsds > 0;
482 } 478 }
483 479
484 apr_status_t status; 480 LLScopedVolatileAPRPool scoped_pool;
485 LLAPRPool pool;
486 status = pool.getStatus() ;
487 ll_apr_assert_status(status);
488 481
489 for (int i = 0; i < ARES_GETSOCK_MAXNUM; i++) 482 for (int i = 0; i < ARES_GETSOCK_MAXNUM; i++)
490 { 483 {
@@ -501,7 +494,7 @@ bool LLAres::process(U64 timeout)
501 494
502 apr_socket_t *aprSock = NULL; 495 apr_socket_t *aprSock = NULL;
503 496
504 status = apr_os_sock_put(&aprSock, (apr_os_sock_t *) &socks[i], pool.getAPRPool()); 497 apr_status_t status = apr_os_sock_put(&aprSock, (apr_os_sock_t *) &socks[i], scoped_pool);
505 if (status != APR_SUCCESS) 498 if (status != APR_SUCCESS)
506 { 499 {
507 ll_apr_warn_status(status); 500 ll_apr_warn_status(status);
@@ -510,7 +503,7 @@ bool LLAres::process(U64 timeout)
510 503
511 aprFds[nactive].desc.s = aprSock; 504 aprFds[nactive].desc.s = aprSock;
512 aprFds[nactive].desc_type = APR_POLL_SOCKET; 505 aprFds[nactive].desc_type = APR_POLL_SOCKET;
513 aprFds[nactive].p = pool.getAPRPool(); 506 aprFds[nactive].p = scoped_pool;
514 aprFds[nactive].rtnevents = 0; 507 aprFds[nactive].rtnevents = 0;
515 aprFds[nactive].client_data = &socks[i]; 508 aprFds[nactive].client_data = &socks[i];
516 509
@@ -519,7 +512,7 @@ bool LLAres::process(U64 timeout)
519 512
520 if (nactive > 0) 513 if (nactive > 0)
521 { 514 {
522 status = apr_poll(aprFds, nactive, &nsds, timeout); 515 apr_status_t status = apr_poll(aprFds, nactive, &nsds, timeout);
523 516
524 if (status != APR_SUCCESS && status != APR_TIMEUP) 517 if (status != APR_SUCCESS && status != APR_TIMEUP)
525 { 518 {
diff --git a/linden/indra/llmessage/llcurl.cpp b/linden/indra/llmessage/llcurl.cpp
index 202332c..9ecfee4 100644
--- a/linden/indra/llmessage/llcurl.cpp
+++ b/linden/indra/llmessage/llcurl.cpp
@@ -1020,7 +1020,7 @@ void LLCurl::initClass()
1020 S32 mutex_count = CRYPTO_num_locks(); 1020 S32 mutex_count = CRYPTO_num_locks();
1021 for (S32 i=0; i<mutex_count; i++) 1021 for (S32 i=0; i<mutex_count; i++)
1022 { 1022 {
1023 sSSLMutex.push_back(new LLMutex(NULL)); 1023 sSSLMutex.push_back(new LLMutex);
1024 } 1024 }
1025 CRYPTO_set_id_callback(&LLCurl::ssl_thread_id); 1025 CRYPTO_set_id_callback(&LLCurl::ssl_thread_id);
1026 CRYPTO_set_locking_callback(&LLCurl::ssl_locking_callback); 1026 CRYPTO_set_locking_callback(&LLCurl::ssl_locking_callback);
diff --git a/linden/indra/llmessage/lliohttpserver.cpp b/linden/indra/llmessage/lliohttpserver.cpp
index 83dfa94..8ad052b 100644
--- a/linden/indra/llmessage/lliohttpserver.cpp
+++ b/linden/indra/llmessage/lliohttpserver.cpp
@@ -948,13 +948,9 @@ private:
948 948
949 949
950// static 950// static
951LLHTTPNode& LLIOHTTPServer::create( 951LLHTTPNode& LLIOHTTPServer::create(LLPumpIO& pump, U16 port)
952 apr_pool_t* pool, LLPumpIO& pump, U16 port)
953{ 952{
954 LLSocket::ptr_t socket = LLSocket::create( 953 LLSocket::ptr_t socket = LLSocket::create(LLSocket::STREAM_TCP, port);
955 pool,
956 LLSocket::STREAM_TCP,
957 port);
958 if(!socket) 954 if(!socket)
959 { 955 {
960 llerrs << "Unable to initialize socket" << llendl; 956 llerrs << "Unable to initialize socket" << llendl;
@@ -963,7 +959,7 @@ LLHTTPNode& LLIOHTTPServer::create(
963 LLHTTPResponseFactory* factory = new LLHTTPResponseFactory; 959 LLHTTPResponseFactory* factory = new LLHTTPResponseFactory;
964 boost::shared_ptr<LLChainIOFactory> factory_ptr(factory); 960 boost::shared_ptr<LLChainIOFactory> factory_ptr(factory);
965 961
966 LLIOServerSocket* server = new LLIOServerSocket(pool, socket, factory_ptr); 962 LLIOServerSocket* server = new LLIOServerSocket(socket, factory_ptr);
967 963
968 LLPumpIO::chain_t chain; 964 LLPumpIO::chain_t chain;
969 chain.push_back(LLIOPipe::ptr_t(server)); 965 chain.push_back(LLIOPipe::ptr_t(server));
diff --git a/linden/indra/llmessage/lliohttpserver.h b/linden/indra/llmessage/lliohttpserver.h
index d1c9bdd..d2a8e2a 100644
--- a/linden/indra/llmessage/lliohttpserver.h
+++ b/linden/indra/llmessage/lliohttpserver.h
@@ -57,7 +57,7 @@ class LLIOHTTPServer
57public: 57public:
58 typedef void (*timing_callback_t)(const char* hashed_name, F32 time, void* data); 58 typedef void (*timing_callback_t)(const char* hashed_name, F32 time, void* data);
59 59
60 static LLHTTPNode& create(apr_pool_t* pool, LLPumpIO& pump, U16 port); 60 static LLHTTPNode& create(LLPumpIO& pump, U16 port);
61 /**< Creates an HTTP wire server on the pump for the given TCP port. 61 /**< Creates an HTTP wire server on the pump for the given TCP port.
62 * 62 *
63 * Returns the root node of the new server. Add LLHTTPNode instances 63 * Returns the root node of the new server. Add LLHTTPNode instances
diff --git a/linden/indra/llmessage/lliosocket.cpp b/linden/indra/llmessage/lliosocket.cpp
index 7ec577c..686c037 100644
--- a/linden/indra/llmessage/lliosocket.cpp
+++ b/linden/indra/llmessage/lliosocket.cpp
@@ -41,6 +41,7 @@
41#include "llhost.h" 41#include "llhost.h"
42#include "llmemtype.h" 42#include "llmemtype.h"
43#include "llpumpio.h" 43#include "llpumpio.h"
44#include "llthread.h"
44 45
45// 46//
46// constants 47// constants
@@ -104,51 +105,31 @@ void ll_debug_socket(const char* msg, apr_socket_t* apr_sock)
104/// 105///
105 106
106// static 107// static
107LLSocket::ptr_t LLSocket::create(apr_pool_t* pool, EType type, U16 port) 108LLSocket::ptr_t LLSocket::create(EType type, U16 port)
108{ 109{
109 LLMemType m1(LLMemType::MTYPE_IO_TCP); 110 LLMemType m1(LLMemType::MTYPE_IO_TCP);
110 LLSocket::ptr_t rv;
111 apr_socket_t* socket = NULL;
112 apr_pool_t* new_pool = NULL;
113 apr_status_t status = APR_EGENERAL; 111 apr_status_t status = APR_EGENERAL;
114 112 LLSocket::ptr_t rv(new LLSocket);
115 // create a pool for the socket
116 status = apr_pool_create(&new_pool, pool);
117 if(ll_apr_warn_status(status))
118 {
119 if(new_pool) apr_pool_destroy(new_pool);
120 return rv;
121 }
122 113
123 if(STREAM_TCP == type) 114 if(STREAM_TCP == type)
124 { 115 {
125 status = apr_socket_create( 116 status = apr_socket_create(&rv->mSocket, APR_INET, SOCK_STREAM, APR_PROTO_TCP, rv->mPool());
126 &socket,
127 APR_INET,
128 SOCK_STREAM,
129 APR_PROTO_TCP,
130 new_pool);
131 } 117 }
132 else if(DATAGRAM_UDP == type) 118 else if(DATAGRAM_UDP == type)
133 { 119 {
134 status = apr_socket_create( 120 status = apr_socket_create(&rv->mSocket, APR_INET, SOCK_DGRAM, APR_PROTO_UDP, rv->mPool());
135 &socket,
136 APR_INET,
137 SOCK_DGRAM,
138 APR_PROTO_UDP,
139 new_pool);
140 } 121 }
141 else 122 else
142 { 123 {
143 if(new_pool) apr_pool_destroy(new_pool); 124 rv.reset();
144 return rv; 125 return rv;
145 } 126 }
146 if(ll_apr_warn_status(status)) 127 if(ll_apr_warn_status(status))
147 { 128 {
148 if(new_pool) apr_pool_destroy(new_pool); 129 rv->mSocket = NULL;
130 rv.reset();
149 return rv; 131 return rv;
150 } 132 }
151 rv = ptr_t(new LLSocket(socket, new_pool));
152 if(port > 0) 133 if(port > 0)
153 { 134 {
154 apr_sockaddr_t* sa = NULL; 135 apr_sockaddr_t* sa = NULL;
@@ -158,7 +139,7 @@ LLSocket::ptr_t LLSocket::create(apr_pool_t* pool, EType type, U16 port)
158 APR_UNSPEC, 139 APR_UNSPEC,
159 port, 140 port,
160 0, 141 0,
161 new_pool); 142 rv->mPool());
162 if(ll_apr_warn_status(status)) 143 if(ll_apr_warn_status(status))
163 { 144 {
164 rv.reset(); 145 rv.reset();
@@ -166,8 +147,8 @@ LLSocket::ptr_t LLSocket::create(apr_pool_t* pool, EType type, U16 port)
166 } 147 }
167 // This allows us to reuse the address on quick down/up. This 148 // This allows us to reuse the address on quick down/up. This
168 // is unlikely to create problems. 149 // is unlikely to create problems.
169 ll_apr_warn_status(apr_socket_opt_set(socket, APR_SO_REUSEADDR, 1)); 150 ll_apr_warn_status(apr_socket_opt_set(rv->mSocket, APR_SO_REUSEADDR, 1));
170 status = apr_socket_bind(socket, sa); 151 status = apr_socket_bind(rv->mSocket, sa);
171 if(ll_apr_warn_status(status)) 152 if(ll_apr_warn_status(status))
172 { 153 {
173 rv.reset(); 154 rv.reset();
@@ -181,7 +162,7 @@ LLSocket::ptr_t LLSocket::create(apr_pool_t* pool, EType type, U16 port)
181 // to keep a queue of incoming connections for ACCEPT. 162 // to keep a queue of incoming connections for ACCEPT.
182 lldebugs << "Setting listen state for socket." << llendl; 163 lldebugs << "Setting listen state for socket." << llendl;
183 status = apr_socket_listen( 164 status = apr_socket_listen(
184 socket, 165 rv->mSocket,
185 LL_DEFAULT_LISTEN_BACKLOG); 166 LL_DEFAULT_LISTEN_BACKLOG);
186 if(ll_apr_warn_status(status)) 167 if(ll_apr_warn_status(status))
187 { 168 {
@@ -202,21 +183,28 @@ LLSocket::ptr_t LLSocket::create(apr_pool_t* pool, EType type, U16 port)
202} 183}
203 184
204// static 185// static
205LLSocket::ptr_t LLSocket::create(apr_socket_t* socket, apr_pool_t* pool) 186LLSocket::ptr_t LLSocket::create(apr_status_t& status, LLSocket::ptr_t& listen_socket)
206{ 187{
207 LLMemType m1(LLMemType::MTYPE_IO_TCP); 188 LLMemType m1(LLMemType::MTYPE_IO_TCP);
208 LLSocket::ptr_t rv; 189 if (!listen_socket->getSocket())
209 if(!socket) 190 {
191 status = APR_ENOSOCKET;
192 return LLSocket::ptr_t();
193 }
194 LLSocket::ptr_t rv(new LLSocket);
195 lldebugs << "accepting socket" << llendl;
196 status = apr_socket_accept(&rv->mSocket, listen_socket->getSocket(), rv->mPool());
197 if (status != APR_SUCCESS)
210 { 198 {
199 rv->mSocket = NULL;
200 rv.reset();
211 return rv; 201 return rv;
212 } 202 }
213 rv = ptr_t(new LLSocket(socket, pool));
214 rv->mPort = PORT_EPHEMERAL; 203 rv->mPort = PORT_EPHEMERAL;
215 rv->setOptions(); 204 rv->setOptions();
216 return rv; 205 return rv;
217} 206}
218 207
219
220bool LLSocket::blockingConnect(const LLHost& host) 208bool LLSocket::blockingConnect(const LLHost& host)
221{ 209{
222 if(!mSocket) return false; 210 if(!mSocket) return false;
@@ -229,7 +217,7 @@ bool LLSocket::blockingConnect(const LLHost& host)
229 APR_UNSPEC, 217 APR_UNSPEC,
230 host.getPort(), 218 host.getPort(),
231 0, 219 0,
232 mPool))) 220 mPool())))
233 { 221 {
234 return false; 222 return false;
235 } 223 }
@@ -240,13 +228,11 @@ bool LLSocket::blockingConnect(const LLHost& host)
240 return true; 228 return true;
241} 229}
242 230
243LLSocket::LLSocket(apr_socket_t* socket, apr_pool_t* pool) : 231LLSocket::LLSocket() :
244 mSocket(socket), 232 mSocket(NULL),
245 mPool(pool), 233 mPool(LLThread::tldata().mRootPool),
246 mPort(PORT_INVALID) 234 mPort(PORT_INVALID)
247{ 235{
248 ll_debug_socket("Constructing wholely formed socket", mSocket);
249 LLMemType m1(LLMemType::MTYPE_IO_TCP);
250} 236}
251 237
252LLSocket::~LLSocket() 238LLSocket::~LLSocket()
@@ -258,10 +244,6 @@ LLSocket::~LLSocket()
258 ll_debug_socket("Destroying socket", mSocket); 244 ll_debug_socket("Destroying socket", mSocket);
259 apr_socket_close(mSocket); 245 apr_socket_close(mSocket);
260 } 246 }
261 if(mPool)
262 {
263 apr_pool_destroy(mPool);
264 }
265} 247}
266 248
267void LLSocket::setOptions() 249void LLSocket::setOptions()
@@ -522,10 +504,8 @@ LLIOPipe::EStatus LLIOSocketWriter::process_impl(
522/// 504///
523 505
524LLIOServerSocket::LLIOServerSocket( 506LLIOServerSocket::LLIOServerSocket(
525 apr_pool_t* pool,
526 LLIOServerSocket::socket_t listener, 507 LLIOServerSocket::socket_t listener,
527 factory_t factory) : 508 factory_t factory) :
528 mPool(pool),
529 mListenSocket(listener), 509 mListenSocket(listener),
530 mReactor(factory), 510 mReactor(factory),
531 mInitialized(false), 511 mInitialized(false),
@@ -585,21 +565,15 @@ LLIOPipe::EStatus LLIOServerSocket::process_impl(
585 lldebugs << "accepting socket" << llendl; 565 lldebugs << "accepting socket" << llendl;
586 566
587 PUMP_DEBUG; 567 PUMP_DEBUG;
588 apr_pool_t* new_pool = NULL; 568 apr_status_t status;
589 apr_status_t status = apr_pool_create(&new_pool, mPool); 569 LLSocket::ptr_t llsocket(LLSocket::create(status, mListenSocket));
590 apr_socket_t* socket = NULL;
591 status = apr_socket_accept(
592 &socket,
593 mListenSocket->getSocket(),
594 new_pool);
595 LLSocket::ptr_t llsocket(LLSocket::create(socket, new_pool));
596 //EStatus rv = STATUS_ERROR; 570 //EStatus rv = STATUS_ERROR;
597 if(llsocket) 571 if(llsocket && status == APR_SUCCESS)
598 { 572 {
599 PUMP_DEBUG; 573 PUMP_DEBUG;
600 574
601 apr_sockaddr_t* remote_addr; 575 apr_sockaddr_t* remote_addr;
602 apr_socket_addr_get(&remote_addr, APR_REMOTE, socket); 576 apr_socket_addr_get(&remote_addr, APR_REMOTE, llsocket->getSocket());
603 577
604 char* remote_host_string; 578 char* remote_host_string;
605 apr_sockaddr_ip_get(&remote_host_string, remote_addr); 579 apr_sockaddr_ip_get(&remote_host_string, remote_addr);
@@ -614,7 +588,6 @@ LLIOPipe::EStatus LLIOServerSocket::process_impl(
614 { 588 {
615 chain.push_back(LLIOPipe::ptr_t(new LLIOSocketWriter(llsocket))); 589 chain.push_back(LLIOPipe::ptr_t(new LLIOSocketWriter(llsocket)));
616 pump->addChain(chain, mResponseTimeout); 590 pump->addChain(chain, mResponseTimeout);
617 status = STATUS_OK;
618 } 591 }
619 else 592 else
620 { 593 {
@@ -623,7 +596,8 @@ LLIOPipe::EStatus LLIOServerSocket::process_impl(
623 } 596 }
624 else 597 else
625 { 598 {
626 llwarns << "Unable to create linden socket." << llendl; 599 char buf[256];
600 llwarns << "Unable to accept linden socket: " << apr_strerror(status, buf, sizeof(buf)) << llendl;
627 } 601 }
628 602
629 PUMP_DEBUG; 603 PUMP_DEBUG;
@@ -636,11 +610,10 @@ LLIOPipe::EStatus LLIOServerSocket::process_impl(
636#if 0 610#if 0
637LLIODataSocket::LLIODataSocket( 611LLIODataSocket::LLIODataSocket(
638 U16 suggested_port, 612 U16 suggested_port,
639 U16 start_discovery_port, 613 U16 start_discovery_port) :
640 apr_pool_t* pool) :
641 mSocket(NULL) 614 mSocket(NULL)
642{ 615{
643 if(!pool || (PORT_INVALID == suggested_port)) return; 616 if(PORT_INVALID == suggested_port) return;
644 if(ll_apr_warn_status(apr_socket_create(&mSocket, APR_INET, SOCK_DGRAM, APR_PROTO_UDP, pool))) return; 617 if(ll_apr_warn_status(apr_socket_create(&mSocket, APR_INET, SOCK_DGRAM, APR_PROTO_UDP, pool))) return;
645 apr_sockaddr_t* sa = NULL; 618 apr_sockaddr_t* sa = NULL;
646 if(ll_apr_warn_status(apr_sockaddr_info_get(&sa, APR_ANYADDR, APR_UNSPEC, suggested_port, 0, pool))) return; 619 if(ll_apr_warn_status(apr_sockaddr_info_get(&sa, APR_ANYADDR, APR_UNSPEC, suggested_port, 0, pool))) return;
diff --git a/linden/indra/llmessage/lliosocket.h b/linden/indra/llmessage/lliosocket.h
index ec09ad8..5ad75e9 100644
--- a/linden/indra/llmessage/lliosocket.h
+++ b/linden/indra/llmessage/lliosocket.h
@@ -44,7 +44,6 @@
44 */ 44 */
45 45
46#include "lliopipe.h" 46#include "lliopipe.h"
47#include "apr_pools.h"
48#include "apr_network_io.h" 47#include "apr_network_io.h"
49#include "llchainio.h" 48#include "llchainio.h"
50 49
@@ -94,34 +93,22 @@ public:
94 * socket. If you intend the socket to be known to external 93 * socket. If you intend the socket to be known to external
95 * clients without prior port notification, do not use 94 * clients without prior port notification, do not use
96 * PORT_EPHEMERAL. 95 * PORT_EPHEMERAL.
97 * @param pool The apr pool to use. A child pool will be created
98 * and associated with the socket.
99 * @param type The type of socket to create 96 * @param type The type of socket to create
100 * @param port The port for the socket 97 * @param port The port for the socket
101 * @return A valid socket shared pointer if the call worked. 98 * @return A valid socket shared pointer if the call worked.
102 */ 99 */
103 static ptr_t create( 100 static ptr_t create(
104 apr_pool_t* pool,
105 EType type, 101 EType type,
106 U16 port = PORT_EPHEMERAL); 102 U16 port = PORT_EPHEMERAL);
107 103
108 /** 104 /**
109 * @brief Create a LLSocket when you already have an apr socket. 105 * @brief Create a LLSocket by accepting a connection from a listen socket.
110 * 106 *
111 * This method assumes an ephemeral port. This is typically used 107 * @param status Output. Status of the accept if a valid listen socket was passed.
112 * by calls which spawn a socket such as a call to 108 * @param listen_socket The listen socket to use.
113 * <code>accept()</code> as in the server socket. This call should
114 * not fail if you have a valid apr socket.
115 * Because of the nature of how accept() works, you are expected
116 * to create a new pool for the socket, use that pool for the
117 * accept, and pass it in here where it will be bound with the
118 * socket and destroyed at the same time.
119 * @param socket The apr socket to use
120 * @param pool The pool used to create the socket. *NOTE: The pool
121 * passed in will be DESTROYED.
122 * @return A valid socket shared pointer if the call worked. 109 * @return A valid socket shared pointer if the call worked.
123 */ 110 */
124 static ptr_t create(apr_socket_t* socket, apr_pool_t* pool); 111 static ptr_t create(apr_status_t& status, ptr_t& listen_socket);
125 112
126 /** 113 /**
127 * @brief Perform a blocking connect to a host. Do not use in production. 114 * @brief Perform a blocking connect to a host. Do not use in production.
@@ -156,7 +143,7 @@ protected:
156 * @brief Protected constructor since should only make sockets 143 * @brief Protected constructor since should only make sockets
157 * with one of the two <code>create()</code> calls. 144 * with one of the two <code>create()</code> calls.
158 */ 145 */
159 LLSocket(apr_socket_t* socket, apr_pool_t* pool); 146 LLSocket(void);
160 147
161 /** 148 /**
162 * @brief Set default socket options. 149 * @brief Set default socket options.
@@ -173,8 +160,8 @@ protected:
173 // The apr socket. 160 // The apr socket.
174 apr_socket_t* mSocket; 161 apr_socket_t* mSocket;
175 162
176 // our memory pool 163 // Our memory pool.
177 apr_pool_t* mPool; 164 AIAPRPool mPool;
178 165
179 // The port if we know it. 166 // The port if we know it.
180 U16 mPort; 167 U16 mPort;
@@ -299,7 +286,7 @@ class LLIOServerSocket : public LLIOPipe
299public: 286public:
300 typedef LLSocket::ptr_t socket_t; 287 typedef LLSocket::ptr_t socket_t;
301 typedef boost::shared_ptr<LLChainIOFactory> factory_t; 288 typedef boost::shared_ptr<LLChainIOFactory> factory_t;
302 LLIOServerSocket(apr_pool_t* pool, socket_t listener, factory_t reactor); 289 LLIOServerSocket(socket_t listener, factory_t reactor);
303 virtual ~LLIOServerSocket(); 290 virtual ~LLIOServerSocket();
304 291
305 /** 292 /**
@@ -331,7 +318,6 @@ protected:
331 //@} 318 //@}
332 319
333protected: 320protected:
334 apr_pool_t* mPool;
335 socket_t mListenSocket; 321 socket_t mListenSocket;
336 factory_t mReactor; 322 factory_t mReactor;
337 bool mInitialized; 323 bool mInitialized;
@@ -365,8 +351,7 @@ public:
365 */ 351 */
366 LLIODataSocket( 352 LLIODataSocket(
367 U16 suggested_port, 353 U16 suggested_port,
368 U16 start_discovery_port, 354 U16 start_discovery_port);
369 apr_pool_t* pool);
370 virtual ~LLIODataSocket(); 355 virtual ~LLIODataSocket();
371 356
372protected: 357protected:
diff --git a/linden/indra/llmessage/llmail.cpp b/linden/indra/llmessage/llmail.cpp
index d52ff6c..8850e29 100644
--- a/linden/indra/llmessage/llmail.cpp
+++ b/linden/indra/llmessage/llmail.cpp
@@ -56,6 +56,7 @@
56#include "llstring.h" 56#include "llstring.h"
57#include "lluuid.h" 57#include "lluuid.h"
58#include "net.h" 58#include "net.h"
59#include "aiaprpool.h"
59 60
60// 61//
61// constants 62// constants
@@ -63,7 +64,7 @@
63const size_t LL_MAX_KNOWN_GOOD_MAIL_SIZE = 4096; 64const size_t LL_MAX_KNOWN_GOOD_MAIL_SIZE = 4096;
64 65
65static bool gMailEnabled = true; 66static bool gMailEnabled = true;
66static apr_pool_t* gMailPool; 67static AIAPRPool gMailPool;
67static apr_sockaddr_t* gSockAddr; 68static apr_sockaddr_t* gSockAddr;
68static apr_socket_t* gMailSocket; 69static apr_socket_t* gMailSocket;
69 70
@@ -88,7 +89,7 @@ bool connect_smtp()
88 gSockAddr->sa.sin.sin_family, 89 gSockAddr->sa.sin.sin_family,
89 SOCK_STREAM, 90 SOCK_STREAM,
90 APR_PROTO_TCP, 91 APR_PROTO_TCP,
91 gMailPool); 92 gMailPool());
92 if(ll_apr_warn_status(status)) return false; 93 if(ll_apr_warn_status(status)) return false;
93 status = apr_socket_connect(gMailSocket, gSockAddr); 94 status = apr_socket_connect(gMailSocket, gSockAddr);
94 if(ll_apr_warn_status(status)) 95 if(ll_apr_warn_status(status))
@@ -145,19 +146,19 @@ BOOL LLMail::send(
145} 146}
146 147
147// static 148// static
148void LLMail::init(const std::string& hostname, apr_pool_t* pool) 149void LLMail::init(const std::string& hostname)
149{ 150{
150 gMailSocket = NULL; 151 gMailSocket = NULL;
151 if(hostname.empty() || !pool) 152 if (hostname.empty())
152 { 153 {
153 gMailPool = NULL;
154 gSockAddr = NULL; 154 gSockAddr = NULL;
155 gMailPool.destroy();
155 } 156 }
156 else 157 else
157 { 158 {
158 gMailPool = pool; 159 gMailPool.create();
159 160
160 // collect all the information into a socaddr sturcture. the 161 // Collect all the information into a sockaddr structure. the
161 // documentation is a bit unclear, but I either have to 162 // documentation is a bit unclear, but I either have to
162 // specify APR_UNSPEC or not specify any flags. I am not sure 163 // specify APR_UNSPEC or not specify any flags. I am not sure
163 // which option is better. 164 // which option is better.
@@ -167,7 +168,7 @@ void LLMail::init(const std::string& hostname, apr_pool_t* pool)
167 APR_UNSPEC, 168 APR_UNSPEC,
168 25, 169 25,
169 APR_IPV4_ADDR_OK, 170 APR_IPV4_ADDR_OK,
170 gMailPool); 171 gMailPool());
171 ll_apr_warn_status(status); 172 ll_apr_warn_status(status);
172 } 173 }
173} 174}
diff --git a/linden/indra/llmessage/llmail.h b/linden/indra/llmessage/llmail.h
index 7effb84..7026d93 100644
--- a/linden/indra/llmessage/llmail.h
+++ b/linden/indra/llmessage/llmail.h
@@ -33,15 +33,13 @@
33#ifndef LL_LLMAIL_H 33#ifndef LL_LLMAIL_H
34#define LL_LLMAIL_H 34#define LL_LLMAIL_H
35 35
36typedef struct apr_pool_t apr_pool_t;
37
38#include "llsd.h" 36#include "llsd.h"
39 37
40class LLMail 38class LLMail
41{ 39{
42public: 40public:
43 // if hostname is NULL, then the host is resolved as 'mail' 41 // if hostname is NULL, then the host is resolved as 'mail'
44 static void init(const std::string& hostname, apr_pool_t* pool); 42 static void init(const std::string& hostname);
45 43
46 // Allow all email transmission to be disabled/enabled. 44 // Allow all email transmission to be disabled/enabled.
47 static void enable(bool mail_enabled); 45 static void enable(bool mail_enabled);
diff --git a/linden/indra/llmessage/llpumpio.cpp b/linden/indra/llmessage/llpumpio.cpp
index 8ef2b16..6f10c6b 100644
--- a/linden/indra/llmessage/llpumpio.cpp
+++ b/linden/indra/llmessage/llpumpio.cpp
@@ -43,6 +43,7 @@
43#include "llmemtype.h" 43#include "llmemtype.h"
44#include "llstl.h" 44#include "llstl.h"
45#include "llstat.h" 45#include "llstat.h"
46#include "llthread.h"
46#include "llfasttimer.h" 47#include "llfasttimer.h"
47 48
48// These should not be enabled in production, but they can be 49// These should not be enabled in production, but they can be
@@ -169,14 +170,12 @@ struct ll_delete_apr_pollset_fd_client_data
169/** 170/**
170 * LLPumpIO 171 * LLPumpIO
171 */ 172 */
172LLPumpIO::LLPumpIO(apr_pool_t* pool) : 173LLPumpIO::LLPumpIO(void) :
173 mState(LLPumpIO::NORMAL), 174 mState(LLPumpIO::NORMAL),
174 mRebuildPollset(false), 175 mRebuildPollset(false),
175 mPollset(NULL), 176 mPollset(NULL),
176 mPollsetClientID(0), 177 mPollsetClientID(0),
177 mNextLock(0), 178 mNextLock(0),
178 mPool(NULL),
179 mCurrentPool(NULL),
180 mCurrentPoolReallocCount(0), 179 mCurrentPoolReallocCount(0),
181 mChainsMutex(NULL), 180 mChainsMutex(NULL),
182 mCallbackMutex(NULL), 181 mCallbackMutex(NULL),
@@ -185,21 +184,24 @@ LLPumpIO::LLPumpIO(apr_pool_t* pool) :
185 mCurrentChain = mRunningChains.end(); 184 mCurrentChain = mRunningChains.end();
186 185
187 LLMemType m1(LLMemType::MTYPE_IO_PUMP); 186 LLMemType m1(LLMemType::MTYPE_IO_PUMP);
188 initialize(pool); 187 initialize();
189} 188}
190 189
191LLPumpIO::~LLPumpIO() 190LLPumpIO::~LLPumpIO()
192{ 191{
193 LLMemType m1(LLMemType::MTYPE_IO_PUMP); 192 LLMemType m1(LLMemType::MTYPE_IO_PUMP);
194 cleanup(); 193#if LL_THREADS_APR
195} 194 if (mChainsMutex) apr_thread_mutex_destroy(mChainsMutex);
196 195 if (mCallbackMutex) apr_thread_mutex_destroy(mCallbackMutex);
197bool LLPumpIO::prime(apr_pool_t* pool) 196#endif
198{ 197 mChainsMutex = NULL;
199 LLMemType m1(LLMemType::MTYPE_IO_PUMP); 198 mCallbackMutex = NULL;
200 cleanup(); 199 if(mPollset)
201 initialize(pool); 200 {
202 return ((pool == NULL) ? false : true); 201// lldebugs << "cleaning up pollset" << llendl;
202 apr_pollset_destroy(mPollset);
203 mPollset = NULL;
204 }
203} 205}
204 206
205bool LLPumpIO::addChain(const chain_t& chain, F32 timeout) 207bool LLPumpIO::addChain(const chain_t& chain, F32 timeout)
@@ -359,8 +361,7 @@ bool LLPumpIO::setConditional(LLIOPipe* pipe, const apr_pollfd_t* poll)
359 { 361 {
360 // each fd needs a pool to work with, so if one was 362 // each fd needs a pool to work with, so if one was
361 // not specified, use this pool. 363 // not specified, use this pool.
362 // *FIX: Should it always be this pool? 364 value.second.p = (*mCurrentChain).mDescriptorsPool->operator()();
363 value.second.p = mPool;
364 } 365 }
365 value.second.client_data = new S32(++mPollsetClientID); 366 value.second.client_data = new S32(++mPollsetClientID);
366 (*mCurrentChain).mDescriptors.push_back(value); 367 (*mCurrentChain).mDescriptors.push_back(value);
@@ -827,39 +828,15 @@ void LLPumpIO::control(LLPumpIO::EControl op)
827 } 828 }
828} 829}
829 830
830void LLPumpIO::initialize(apr_pool_t* pool) 831void LLPumpIO::initialize(void)
831{ 832{
832 LLMemType m1(LLMemType::MTYPE_IO_PUMP); 833 LLMemType m1(LLMemType::MTYPE_IO_PUMP);
833 if(!pool) return; 834 mPool.create();
834#if LL_THREADS_APR 835#if LL_THREADS_APR
835 // SJB: Windows defaults to NESTED and OSX defaults to UNNESTED, so use UNNESTED explicitly. 836 // SJB: Windows defaults to NESTED and OSX defaults to UNNESTED, so use UNNESTED explicitly.
836 apr_thread_mutex_create(&mChainsMutex, APR_THREAD_MUTEX_UNNESTED, pool); 837 apr_thread_mutex_create(&mChainsMutex, APR_THREAD_MUTEX_UNNESTED, mPool());
837 apr_thread_mutex_create(&mCallbackMutex, APR_THREAD_MUTEX_UNNESTED, pool); 838 apr_thread_mutex_create(&mCallbackMutex, APR_THREAD_MUTEX_UNNESTED, mPool());
838#endif
839 mPool = pool;
840}
841
842void LLPumpIO::cleanup()
843{
844 LLMemType m1(LLMemType::MTYPE_IO_PUMP);
845#if LL_THREADS_APR
846 if(mChainsMutex) apr_thread_mutex_destroy(mChainsMutex);
847 if(mCallbackMutex) apr_thread_mutex_destroy(mCallbackMutex);
848#endif 839#endif
849 mChainsMutex = NULL;
850 mCallbackMutex = NULL;
851 if(mPollset)
852 {
853// lldebugs << "cleaning up pollset" << llendl;
854 apr_pollset_destroy(mPollset);
855 mPollset = NULL;
856 }
857 if(mCurrentPool)
858 {
859 apr_pool_destroy(mCurrentPool);
860 mCurrentPool = NULL;
861 }
862 mPool = NULL;
863} 840}
864 841
865void LLPumpIO::rebuildPollset() 842void LLPumpIO::rebuildPollset()
@@ -887,21 +864,19 @@ void LLPumpIO::rebuildPollset()
887 if(mCurrentPool 864 if(mCurrentPool
888 && (0 == (++mCurrentPoolReallocCount % POLLSET_POOL_RECYCLE_COUNT))) 865 && (0 == (++mCurrentPoolReallocCount % POLLSET_POOL_RECYCLE_COUNT)))
889 { 866 {
890 apr_pool_destroy(mCurrentPool); 867 mCurrentPool.destroy();
891 mCurrentPool = NULL;
892 mCurrentPoolReallocCount = 0; 868 mCurrentPoolReallocCount = 0;
893 } 869 }
894 if(!mCurrentPool) 870 if(!mCurrentPool)
895 { 871 {
896 apr_status_t status = apr_pool_create(&mCurrentPool, mPool); 872 mCurrentPool.create(mPool);
897 (void)ll_apr_warn_status(status);
898 } 873 }
899 874
900 // add all of the file descriptors 875 // add all of the file descriptors
901 run_it = mRunningChains.begin(); 876 run_it = mRunningChains.begin();
902 LLChainInfo::conditionals_t::iterator fd_it; 877 LLChainInfo::conditionals_t::iterator fd_it;
903 LLChainInfo::conditionals_t::iterator fd_end; 878 LLChainInfo::conditionals_t::iterator fd_end;
904 apr_pollset_create(&mPollset, size, mCurrentPool, 0); 879 apr_pollset_create(&mPollset, size, mCurrentPool(), 0);
905 for(; run_it != run_end; ++run_it) 880 for(; run_it != run_end; ++run_it)
906 { 881 {
907 fd_it = (*run_it).mDescriptors.begin(); 882 fd_it = (*run_it).mDescriptors.begin();
@@ -1159,7 +1134,8 @@ bool LLPumpIO::handleChainError(
1159LLPumpIO::LLChainInfo::LLChainInfo() : 1134LLPumpIO::LLChainInfo::LLChainInfo() :
1160 mInit(false), 1135 mInit(false),
1161 mLock(0), 1136 mLock(0),
1162 mEOS(false) 1137 mEOS(false),
1138 mDescriptorsPool(new AIAPRPool(LLThread::tldata().mRootPool))
1163{ 1139{
1164 LLMemType m1(LLMemType::MTYPE_IO_PUMP); 1140 LLMemType m1(LLMemType::MTYPE_IO_PUMP);
1165 mTimer.setTimerExpirySec(DEFAULT_CHAIN_EXPIRY_SECS); 1141 mTimer.setTimerExpirySec(DEFAULT_CHAIN_EXPIRY_SECS);
diff --git a/linden/indra/llmessage/llpumpio.h b/linden/indra/llmessage/llpumpio.h
index fc0bfab..2666be0 100644
--- a/linden/indra/llmessage/llpumpio.h
+++ b/linden/indra/llmessage/llpumpio.h
@@ -36,11 +36,12 @@
36#define LL_LLPUMPIO_H 36#define LL_LLPUMPIO_H
37 37
38#include <set> 38#include <set>
39#include <boost/shared_ptr.hpp>
39#if LL_LINUX // needed for PATH_MAX in APR. 40#if LL_LINUX // needed for PATH_MAX in APR.
40#include <sys/param.h> 41#include <sys/param.h>
41#endif 42#endif
42 43
43#include "apr_pools.h" 44#include "aiaprpool.h"
44#include "llbuffer.h" 45#include "llbuffer.h"
45#include "llframetimer.h" 46#include "llframetimer.h"
46#include "lliopipe.h" 47#include "lliopipe.h"
@@ -64,9 +65,8 @@ extern const F32 NEVER_CHAIN_EXPIRY_SECS;
64 * <code>pump()</code> on a thread used for IO and call 65 * <code>pump()</code> on a thread used for IO and call
65 * <code>respond()</code> on a thread that is expected to do higher 66 * <code>respond()</code> on a thread that is expected to do higher
66 * level processing. You can call almost any other method from any 67 * level processing. You can call almost any other method from any
67 * thread - see notes for each method for details. In order for the 68 * thread - see notes for each method for details.
68 * threading abstraction to work, you need to call <code>prime()</code> 69 *
69 * with a valid apr pool.
70 * A pump instance manages much of the state for the pipe, including 70 * A pump instance manages much of the state for the pipe, including
71 * the list of pipes in the chain, the channel for each element in the 71 * the list of pipes in the chain, the channel for each element in the
72 * chain, the buffer, and if any pipe has marked the stream or process 72 * chain, the buffer, and if any pipe has marked the stream or process
@@ -85,7 +85,7 @@ public:
85 /** 85 /**
86 * @brief Constructor. 86 * @brief Constructor.
87 */ 87 */
88 LLPumpIO(apr_pool_t* pool); 88 LLPumpIO(void);
89 89
90 /** 90 /**
91 * @brief Destructor. 91 * @brief Destructor.
@@ -93,17 +93,6 @@ public:
93 ~LLPumpIO(); 93 ~LLPumpIO();
94 94
95 /** 95 /**
96 * @brief Prepare this pump for usage.
97 *
98 * If you fail to call this method prior to use, the pump will
99 * try to work, but will not come with any thread locking
100 * mechanisms.
101 * @param pool The apr pool to use.
102 * @return Returns true if the pump is primed.
103 */
104 bool prime(apr_pool_t* pool);
105
106 /**
107 * @brief Typedef for having a chain of pipes. 96 * @brief Typedef for having a chain of pipes.
108 */ 97 */
109 typedef std::vector<LLIOPipe::ptr_t> chain_t; 98 typedef std::vector<LLIOPipe::ptr_t> chain_t;
@@ -374,6 +363,7 @@ protected:
374 typedef std::pair<LLIOPipe::ptr_t, apr_pollfd_t> pipe_conditional_t; 363 typedef std::pair<LLIOPipe::ptr_t, apr_pollfd_t> pipe_conditional_t;
375 typedef std::vector<pipe_conditional_t> conditionals_t; 364 typedef std::vector<pipe_conditional_t> conditionals_t;
376 conditionals_t mDescriptors; 365 conditionals_t mDescriptors;
366 boost::shared_ptr<AIAPRPool> mDescriptorsPool;
377 }; 367 };
378 368
379 // All the running chains & info 369 // All the running chains & info
@@ -392,9 +382,9 @@ protected:
392 callbacks_t mPendingCallbacks; 382 callbacks_t mPendingCallbacks;
393 callbacks_t mCallbacks; 383 callbacks_t mCallbacks;
394 384
395 // memory allocator for pollsets & mutexes. 385 // Memory pool for pollsets & mutexes.
396 apr_pool_t* mPool; 386 AIAPRPool mPool;
397 apr_pool_t* mCurrentPool; 387 AIAPRPool mCurrentPool;
398 S32 mCurrentPoolReallocCount; 388 S32 mCurrentPoolReallocCount;
399 389
400#if LL_THREADS_APR 390#if LL_THREADS_APR
@@ -406,8 +396,7 @@ protected:
406#endif 396#endif
407 397
408protected: 398protected:
409 void initialize(apr_pool_t* pool); 399 void initialize();
410 void cleanup();
411 400
412 /** 401 /**
413 * @brief Given the internal state of the chains, rebuild the pollset 402 * @brief Given the internal state of the chains, rebuild the pollset
diff --git a/linden/indra/llmessage/llurlrequest.cpp b/linden/indra/llmessage/llurlrequest.cpp
index 46e976f..87f0116 100644
--- a/linden/indra/llmessage/llurlrequest.cpp
+++ b/linden/indra/llmessage/llurlrequest.cpp
@@ -45,6 +45,7 @@
45#include "llstring.h" 45#include "llstring.h"
46#include "apr_env.h" 46#include "apr_env.h"
47#include "llapr.h" 47#include "llapr.h"
48#include "llscopedvolatileaprpool.h"
48static const U32 HTTP_STATUS_PIPE_ERROR = 499; 49static const U32 HTTP_STATUS_PIPE_ERROR = 499;
49 50
50/** 51/**
@@ -161,27 +162,31 @@ void LLURLRequest::setCallback(LLURLRequestComplete* callback)
161// is called with use_proxy = FALSE 162// is called with use_proxy = FALSE
162void LLURLRequest::useProxy(bool use_proxy) 163void LLURLRequest::useProxy(bool use_proxy)
163{ 164{
164 static char *env_proxy; 165 static std::string env_proxy;
165 166
166 if (use_proxy && (env_proxy == NULL)) 167 if (use_proxy && env_proxy.empty())
167 { 168 {
168 apr_status_t status; 169 char* env_proxy_str;
169 LLAPRPool pool; 170 LLScopedVolatileAPRPool scoped_pool;
170 status = apr_env_get(&env_proxy, "ALL_PROXY", pool.getAPRPool()); 171 apr_status_t status = apr_env_get(&env_proxy_str, "ALL_PROXY", scoped_pool);
171 if (status != APR_SUCCESS) 172 if (status != APR_SUCCESS)
172 { 173 {
173 status = apr_env_get(&env_proxy, "http_proxy", pool.getAPRPool()); 174 status = apr_env_get(&env_proxy_str, "http_proxy", scoped_pool);
174 } 175 }
175 if (status != APR_SUCCESS) 176 if (status != APR_SUCCESS)
176 { 177 {
177 use_proxy = FALSE; 178 use_proxy = false;
178 } 179 }
180 else
181 {
182 // env_proxy_str is stored in the scoped_pool, so we have to make a copy.
183 env_proxy = env_proxy_str;
184 }
179 } 185 }
180 186
187 lldebugs << "use_proxy = " << (use_proxy?'Y':'N') << ", env_proxy = \"" << env_proxy << "\"" << llendl;
181 188
182 lldebugs << "use_proxy = " << (use_proxy?'Y':'N') << ", env_proxy = " << (env_proxy ? env_proxy : "(null)") << llendl; 189 if (use_proxy)
183
184 if (env_proxy && use_proxy)
185 { 190 {
186 mDetail->mCurlRequest->setoptString(CURLOPT_PROXY, env_proxy); 191 mDetail->mCurlRequest->setoptString(CURLOPT_PROXY, env_proxy);
187 } 192 }
diff --git a/linden/indra/llmessage/message.cpp b/linden/indra/llmessage/message.cpp
index 7e8aff1..53036bc 100644
--- a/linden/indra/llmessage/message.cpp
+++ b/linden/indra/llmessage/message.cpp
@@ -103,8 +103,10 @@ std::string get_shared_secret();
103class LLMessagePollInfo 103class LLMessagePollInfo
104{ 104{
105public: 105public:
106 LLMessagePollInfo(void) : mPool(LLThread::tldata().mRootPool) { }
106 apr_socket_t *mAPRSocketp; 107 apr_socket_t *mAPRSocketp;
107 apr_pollfd_t mPollFD; 108 apr_pollfd_t mPollFD;
109 AIAPRPool mPool;
108}; 110};
109 111
110namespace 112namespace
@@ -291,20 +293,13 @@ LLMessageSystem::LLMessageSystem(const std::string& filename, U32 port,
291 } 293 }
292// LL_DEBUGS("Messaging") << << "*** port: " << mPort << llendl; 294// LL_DEBUGS("Messaging") << << "*** port: " << mPort << llendl;
293 295
294 // 296 mPollInfop = new LLMessagePollInfo;
295 // Create the data structure that we can poll on 297
296 //
297 if (!gAPRPoolp)
298 {
299 LL_ERRS("Messaging") << "No APR pool before message system initialization!" << llendl;
300 ll_init_apr();
301 }
302 apr_socket_t *aprSocketp = NULL; 298 apr_socket_t *aprSocketp = NULL;
303 apr_os_sock_put(&aprSocketp, (apr_os_sock_t*)&mSocket, gAPRPoolp); 299 apr_os_sock_put(&aprSocketp, (apr_os_sock_t*)&mSocket, mPollInfop->mPool());
304 300
305 mPollInfop = new LLMessagePollInfo;
306 mPollInfop->mAPRSocketp = aprSocketp; 301 mPollInfop->mAPRSocketp = aprSocketp;
307 mPollInfop->mPollFD.p = gAPRPoolp; 302 mPollInfop->mPollFD.p = mPollInfop->mPool();
308 mPollInfop->mPollFD.desc_type = APR_POLL_SOCKET; 303 mPollInfop->mPollFD.desc_type = APR_POLL_SOCKET;
309 mPollInfop->mPollFD.reqevents = APR_POLLIN; 304 mPollInfop->mPollFD.reqevents = APR_POLLIN;
310 mPollInfop->mPollFD.rtnevents = 0; 305 mPollInfop->mPollFD.rtnevents = 0;