Skip to content

Commit

Permalink
[api] Configuration.listen() doesn't take a second options parameter …
Browse files Browse the repository at this point in the history
…when using with a ListenerArray, which itself can be created with options
  • Loading branch information
pajama-coder committed Sep 3, 2023
1 parent 0bac17d commit e01a3cb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
7 changes: 3 additions & 4 deletions src/api/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,12 @@ void Configuration::listen(const std::string &port, pjs::Object *options) {
FilterConfigurator::set_pipeline_config(&config);
}

void Configuration::listen(ListenerArray *listeners, pjs::Object *options) {
void Configuration::listen(ListenerArray *listeners) {
check_integrity();
m_listens.emplace_back();
auto &config = m_listens.back();
config.index = next_pipeline_index();
config.listeners = listeners;
config.listeners->set_default_options(options);
config.ip = "?";
config.port = -1;
FilterConfigurator::set_pipeline_config(&config);
Expand Down Expand Up @@ -2305,8 +2304,8 @@ template<> void ClassDef<Configuration>::init() {
} else if (ctx.try_arguments(1, &port, &options)) {
thiz->as<Configuration>()->listen(port, options);
result.set(thiz);
} else if (ctx.try_arguments(1, &listeners, &options)) {
thiz->as<Configuration>()->listen(listeners, options);
} else if (ctx.try_arguments(1, &listeners)) {
thiz->as<Configuration>()->listen(listeners);
result.set(thiz);
} else {
ctx.error_argument_type(0, "a number, string or ListenerArray");
Expand Down
2 changes: 1 addition & 1 deletion src/api/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class Configuration : public pjs::ObjectTemplate<Configuration, FilterConfigurat

void listen(int port, pjs::Object *options);
void listen(const std::string &port, pjs::Object *options);
void listen(ListenerArray *listeners, pjs::Object *options);
void listen(ListenerArray *listeners);
void task(const std::string &when);
void watch(const std::string &filename);
void exit();
Expand Down
9 changes: 3 additions & 6 deletions src/listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,6 @@ void ListenerArray::set_listeners(pjs::Array *array) {
m_listeners.swap(listeners);
}

void ListenerArray::set_default_options(pjs::Object *options) {
m_default_options = options;
}

void ListenerArray::apply(Worker *worker, PipelineLayout *layout) {
if (m_worker) {
throw std::runtime_error("ListenerArray is being listened already");
Expand Down Expand Up @@ -531,8 +527,9 @@ using namespace pipy;
template<> void ClassDef<ListenerArray>::init() {
ctor([](Context &ctx) -> Object* {
Array *listeners = nullptr;
if (!ctx.arguments(0, &listeners)) return nullptr;
auto la = ListenerArray::make();
Object *options = nullptr;
if (!ctx.arguments(0, &listeners, &options)) return nullptr;
auto la = ListenerArray::make(options);
if (listeners) {
try {
la->set_listeners(listeners);
Expand Down
4 changes: 2 additions & 2 deletions src/listener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ class ListenerArray : public pjs::ObjectTemplate<ListenerArray> {
auto remove_listener(int port, pjs::Object *options = nullptr) -> Listener*;
auto remove_listener(pjs::Str *port, pjs::Object *options = nullptr) -> Listener*;
void set_listeners(pjs::Array *array);
void set_default_options(pjs::Object *options);
void apply(Worker *worker, PipelineLayout *layout);

private:
ListenerArray() {}
ListenerArray(pjs::Object *options = nullptr)
: m_default_options(options) {}

void get_ip_port(const std::string &ip_port, std::string &ip, int &port);

Expand Down

0 comments on commit e01a3cb

Please sign in to comment.