Changeset 729
- Timestamp:
- 06/30/08 18:45:43 (2 years ago)
- Files:
-
- branches/raggi/ext/cmain.cpp (modified) (35 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/raggi/ext/cmain.cpp
r679 r729 3 3 $Id$ 4 4 5 File: 6 Date: 5 File: cmain.cpp 6 Date: 06Apr06 7 7 8 8 Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved. … … 25 25 static int bUseKqueue = 0; 26 26 27 extern "C" void ensure_eventmachine (const char *caller = "unknown caller") 28 { 29 if (!EventMachine) { 30 int err_size = 128; 31 char err_string[err_size]; 32 snprintf (err_string, err_size, "eventmachine not initialized: %s", caller); 33 throw std::runtime_error (err_string); 34 } 35 } 27 36 28 37 /*********************** … … 36 45 //InstallSignalHandlers(); 37 46 if (EventMachine) 38 throw std::runtime_error (" already initialized");47 throw std::runtime_error ("eventmachine already initialized: evma_initialize_library"); 39 48 EventMachine = new EventMachine_t (cb); 40 49 if (bUseEpoll) … … 51 60 extern "C" void evma_release_library() 52 61 { 53 if (!EventMachine) 54 throw std::runtime_error ("not initialized"); 62 ensure_eventmachine("evma_release_library"); 55 63 delete EventMachine; 56 64 EventMachine = NULL; … … 64 72 extern "C" void evma_run_machine() 65 73 { 66 if (!EventMachine) 67 throw std::runtime_error ("not initialized"); 74 ensure_eventmachine("evma_run_machine"); 68 75 EventMachine->Run(); 69 76 } … … 76 83 extern "C" const char *evma_install_oneshot_timer (int seconds) 77 84 { 78 if (!EventMachine) 79 throw std::runtime_error ("not initialized"); 85 ensure_eventmachine("evma_install_oneshot_timer"); 80 86 return EventMachine->InstallOneshotTimer (seconds); 81 87 } … … 88 94 extern "C" const char *evma_connect_to_server (const char *server, int port) 89 95 { 90 if (!EventMachine) 91 throw std::runtime_error ("not initialized"); 96 ensure_eventmachine("evma_connect_to_server"); 92 97 return EventMachine->ConnectToServer (server, port); 93 98 } … … 99 104 extern "C" const char *evma_connect_to_unix_server (const char *server) 100 105 { 101 if (!EventMachine) 102 throw std::runtime_error ("not initialized"); 106 ensure_eventmachine("evma_connect_to_unix_server"); 103 107 return EventMachine->ConnectToUnixServer (server); 104 108 } … … 111 115 extern "C" const char *evma_create_tcp_server (const char *address, int port) 112 116 { 113 if (!EventMachine) 114 throw std::runtime_error ("not initialized"); 117 ensure_eventmachine("evma_create_tcp_server"); 115 118 return EventMachine->CreateTcpServer (address, port); 116 119 } … … 122 125 extern "C" const char *evma_create_unix_domain_server (const char *filename) 123 126 { 124 if (!EventMachine) 125 throw std::runtime_error ("not initialized"); 127 ensure_eventmachine("evma_create_unix_domain_server"); 126 128 return EventMachine->CreateUnixDomainServer (filename); 127 129 } … … 133 135 extern "C" const char *evma_open_datagram_socket (const char *address, int port) 134 136 { 135 if (!EventMachine) 136 throw std::runtime_error ("not initialized"); 137 ensure_eventmachine("evma_open_datagram_socket"); 137 138 return EventMachine->OpenDatagramSocket (address, port); 138 139 } … … 144 145 extern "C" const char *evma_open_keyboard() 145 146 { 146 if (!EventMachine) 147 throw std::runtime_error ("not initialized"); 147 ensure_eventmachine("evma_open_keyboard"); 148 148 return EventMachine->OpenKeyboard(); 149 149 } … … 157 157 extern "C" int evma_send_data_to_connection (const char *binding, const char *data, int data_length) 158 158 { 159 if (!EventMachine) 160 throw std::runtime_error ("not initialized"); 159 ensure_eventmachine("evma_send_data_to_connection"); 161 160 return ConnectionDescriptor::SendDataToConnection (binding, data, data_length); 162 161 } … … 168 167 extern "C" int evma_send_datagram (const char *binding, const char *data, int data_length, const char *address, int port) 169 168 { 170 if (!EventMachine) 171 throw std::runtime_error ("not initialized"); 169 ensure_eventmachine("evma_send_datagram"); 172 170 return DatagramDescriptor::SendDatagram (binding, data, data_length, address, port); 173 171 } … … 180 178 extern "C" void evma_close_connection (const char *binding, int after_writing) 181 179 { 182 if (!EventMachine) 183 throw std::runtime_error ("not initialized"); 180 ensure_eventmachine("evma_close_connection"); 184 181 ConnectionDescriptor::CloseConnection (binding, (after_writing ? true : false)); 185 182 } … … 191 188 extern "C" int evma_report_connection_error_status (const char *binding) 192 189 { 193 if (!EventMachine) 194 throw std::runtime_error ("not initialized"); 190 ensure_eventmachine("evma_report_connection_error_status"); 195 191 return ConnectionDescriptor::ReportErrorStatus (binding); 196 192 } … … 202 198 extern "C" void evma_stop_tcp_server (const char *binding) 203 199 { 204 if (!EventMachine) 205 throw std::runtime_error ("not initialized"); 200 ensure_eventmachine("evma_stop_tcp_server"); 206 201 AcceptorDescriptor::StopAcceptor (binding); 207 202 } … … 214 209 extern "C" void evma_stop_machine() 215 210 { 216 if (!EventMachine) 217 throw std::runtime_error ("not initialized"); 211 ensure_eventmachine("evma_stop_machine"); 218 212 EventMachine->ScheduleHalt(); 219 213 } … … 226 220 extern "C" void evma_start_tls (const char *binding) 227 221 { 228 if (!EventMachine) 229 throw std::runtime_error ("not initialized"); 222 ensure_eventmachine("evma_start_tls"); 230 223 EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding)); 231 224 if (ed) … … 239 232 extern "C" void evma_set_tls_parms (const char *binding, const char *privatekey_filename, const char *certchain_filename) 240 233 { 241 if (!EventMachine) 242 throw std::runtime_error ("not initialized"); 234 ensure_eventmachine("evma_set_tls_parms"); 243 235 EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding)); 244 236 if (ed) … … 253 245 extern "C" int evma_get_peername (const char *binding, struct sockaddr *sa) 254 246 { 255 if (!EventMachine) 256 throw std::runtime_error ("not initialized"); 247 ensure_eventmachine("evma_get_peername"); 257 248 EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding)); 258 249 if (ed) { … … 269 260 extern "C" int evma_get_sockname (const char *binding, struct sockaddr *sa) 270 261 { 271 if (!EventMachine) 272 throw std::runtime_error ("not initialized"); 262 ensure_eventmachine("evma_get_sockname"); 273 263 EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding)); 274 264 if (ed) { … … 285 275 extern "C" int evma_get_subprocess_pid (const char *binding, pid_t *pid) 286 276 { 287 if (!EventMachine) 288 throw std::runtime_error ("not initialized"); 277 ensure_eventmachine("evma_get_subprocess_pid"); 289 278 EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding)); 290 279 if (ed) { … … 301 290 extern "C" int evma_get_subprocess_status (const char *binding, int *status) 302 291 { 303 if (!EventMachine) 304 throw std::runtime_error ("not initialized"); 292 ensure_eventmachine("evma_get_subprocess_status"); 305 293 if (status) { 306 294 *status = EventMachine->SubprocessExitStatus; … … 318 306 extern "C" void evma_signal_loopbreak() 319 307 { 320 if (!EventMachine) 321 throw std::runtime_error ("not initialized"); 308 ensure_eventmachine("evma_signal_loopbreak"); 322 309 EventMachine->SignalLoopBreaker(); 323 310 } … … 331 318 extern "C" const char *evma__write_file (const char *filename) 332 319 { 333 if (!EventMachine) 334 throw std::runtime_error ("not initialized"); 320 ensure_eventmachine("evma__write_file"); 335 321 return EventMachine->_OpenFileForWriting (filename); 336 322 } … … 343 329 extern "C" int evma_get_comm_inactivity_timeout (const char *binding, int *value) 344 330 { 345 if (!EventMachine) 346 throw std::runtime_error ("not initialized"); 331 ensure_eventmachine("evma_get_comm_inactivity_timeout"); 347 332 EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding)); 348 333 if (ed) { … … 359 344 extern "C" int evma_set_comm_inactivity_timeout (const char *binding, int *value) 360 345 { 361 if (!EventMachine) 362 throw std::runtime_error ("not initialized"); 346 ensure_eventmachine("evma_set_comm_inactivity_timeout"); 363 347 EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding)); 364 348 if (ed) { … … 376 360 extern "C" void evma_set_timer_quantum (int interval) 377 361 { 378 if (!EventMachine) 379 throw std::runtime_error ("not initialized"); 362 ensure_eventmachine("evma_set_timer_quantum"); 380 363 EventMachine->SetTimerQuantum (interval); 381 364 } … … 389 372 // This may only be called if the reactor is not running. 390 373 if (EventMachine) 391 throw std::runtime_error (" already initialized");374 throw std::runtime_error ("eventmachine already initialized: evma_set_max_timer_count"); 392 375 EventMachine_t::SetMaxTimerCount (ct); 393 376 } … … 399 382 extern "C" void evma_setuid_string (const char *username) 400 383 { 401 402 384 // We do NOT need to be running an EM instance because this method is static. 385 EventMachine_t::SetuidString (username); 403 386 } 404 387 … … 410 393 extern "C" const char *evma_popen (char * const*cmd_strings) 411 394 { 412 if (!EventMachine) 413 throw std::runtime_error ("not initialized"); 395 ensure_eventmachine("evma_popen"); 414 396 return EventMachine->Socketpair (cmd_strings); 415 397 } … … 422 404 extern "C" int evma_get_outbound_data_size (const char *binding) 423 405 { 424 if (!EventMachine) 425 throw std::runtime_error ("not initialized"); 406 ensure_eventmachine("evma_get_outbound_data_size"); 426 407 EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding)); 427 408 return ed ? ed->GetOutboundDataSize() : 0; … … 484 465 int r; 485 466 486 if (!EventMachine) 487 throw std::runtime_error("not initialized"); 467 ensure_eventmachine("evma_send_file_data_to_connection"); 488 468 489 469 int Fd = open (filename, O_RDONLY); … … 523 503 } 524 504 525 526 527