Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Raise ruby RuntimeError instead of std::runtime_error when built for …
Browse files Browse the repository at this point in the history
…ruby (eventmachine#6)
  • Loading branch information
raggi committed Jan 27, 2009
1 parent c6a6d88 commit 488cfac
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions ext/cmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ extern "C" void ensure_eventmachine (const char *caller = "unknown caller")
const int err_size = 128;
char err_string[err_size];
snprintf (err_string, err_size, "eventmachine not initialized: %s", caller);
throw std::runtime_error (err_string);
#ifdef BUILD_FOR_RUBY
rb_raise(rb_eRuntimeError, err_string);
#else
throw std::runtime_error (err_string);
#endif
}
}

Expand All @@ -44,7 +48,11 @@ extern "C" void evma_initialize_library (void(*cb)(const char*, int, const char*
// we're just being linked into.
//InstallSignalHandlers();
if (EventMachine)
throw std::runtime_error ("eventmachine already initialized: evma_initialize_library");
#ifdef BUILD_FOR_RUBY
rb_raise(rb_eRuntimeError, "eventmachine already initialized: evma_initialize_library");
#else
throw std::runtime_error ("eventmachine already initialized: evma_initialize_library");
#endif
EventMachine = new EventMachine_t (cb);
if (bUseEpoll)
EventMachine->_UseEpoll();
Expand Down Expand Up @@ -113,8 +121,7 @@ evma_attach_fd

extern "C" const char *evma_attach_fd (int file_descriptor, int notify_readable, int notify_writable)
{
if (!EventMachine)
throw std::runtime_error ("not initialized");
ensure_eventmachine("evma_attach_fd");
return EventMachine->AttachFD (file_descriptor, (notify_readable ? true : false), (notify_writable ? true : false));
}

Expand All @@ -124,14 +131,16 @@ evma_detach_fd

extern "C" int evma_detach_fd (const char *binding)
{
if (!EventMachine)
throw std::runtime_error ("not initialized");

ensure_eventmachine("evma_dettach_fd");
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
if (ed)
return EventMachine->DetachFD (ed);
else
throw std::runtime_error ("invalid binding to detach");
#ifdef BUILD_FOR_RUBY
rb_raise(rb_eRuntimeError, "invalid binding to detach");
#else
throw std::runtime_error ("invalid binding to detach");
#endif
}

/**********************
Expand Down Expand Up @@ -396,8 +405,13 @@ evma_set_max_timer_count
extern "C" void evma_set_max_timer_count (int ct)
{
// This may only be called if the reactor is not running.

if (EventMachine)
throw std::runtime_error ("eventmachine already initialized: evma_set_max_timer_count");
#ifdef BUILD_FOR_RUBY
rb_raise(rb_eRuntimeError, "eventmachine already initialized: evma_set_max_timer_count");
#else
throw std::runtime_error ("eventmachine already initialized: evma_set_max_timer_count");
#endif
EventMachine_t::SetMaxTimerCount (ct);
}

Expand Down

0 comments on commit 488cfac

Please sign in to comment.