stop zerogw

24 views
Skip to first unread message

Bogdan Glinskiy

unread,
Dec 12, 2014, 9:56:27 AM12/12/14
to zer...@googlegroups.com
Hello everyone!

Tell me please, how can i stop my zerogw server which is builded in my main program? I am trying to stop it via

ev_invoke(root.loop, &signal_watcher, SIGINT);

and it calls sigint_cb() function, i'm getting message "Received SIGINT, terminating main loop" and that's all. But via CTRL+C it prints that message and then after a few seconds finishes. What am i doing wrong?

I also noticed, that revents with CTRL+C is 1024, and with ev_invoke is 2

Bogdan Glinskiy

unread,
Dec 12, 2014, 11:22:45 AM12/12/14
to zer...@googlegroups.com
Seems, i've got working function. I stop my zerogw server with the help of following function:

void ZeroGW::Stop() {
    raise(SIGINT);
}

Is this is correct?

Paul Colomiets

unread,
Dec 12, 2014, 4:12:12 PM12/12/14
to zer...@googlegroups.com
Hi Bogdan,
It should work. But presumably it's better directly call:

ev_break (loop, EVBREAK_ALL);

However, you need to be in a same thread as zerogw's main loop, and
you need to have a reference to a main loop for this to work.

--
Paul

Bogdan Glinskiy

unread,
Dec 15, 2014, 11:03:33 AM12/15/14
to zer...@googlegroups.com
Well, i use raise(SIGINT) to stop my zerogw server. All the functions config_free(&m_config), ev_loop_destroy(root.loop), etc. do their work, i am getting "Terminated" message, but:

1) websockets don't disconnect after all those function and that message (but new websockets can't connect)
2) after stopping the server and starting it again i am getting error message: "zerogw: No such file or directory", but configuration file is ok and path to it is setted correctly. 

I am a bit confused.. What it can be? 

Thanks a lot,
Bogdan Glinskiy

Paul Colomiets

unread,
Dec 15, 2014, 3:54:13 PM12/15/14
to zer...@googlegroups.com
Hi Bogdan,

On Mon, Dec 15, 2014 at 6:03 PM, Bogdan Glinskiy <fett...@gmail.com> wrote:
> Well, i use raise(SIGINT) to stop my zerogw server. All the functions
> config_free(&m_config), ev_loop_destroy(root.loop), etc. do their work, i am
> getting "Terminated" message, but:
>
> 1) websockets don't disconnect after all those function and that message
> (but new websockets can't connect)

Well, unfortunately it's expected. Zerogw was never designed with
embedding in mind. So zerogw closes listening socket, but doesn't walk
connected sockets, because just exiting process works for zerogw.
Presumably working websockets may even crash the process. Do you need
to restart zerogw itself without restarting process? I don't believe
it's possible without huge amount of work.

> 2) after stopping the server and starting it again i am getting error
> message: "zerogw: No such file or directory", but configuration file is ok
> and path to it is setted correctly.
>
> I am a bit confused.. What it can be?
>

Probably you changed current directory in the process. You can try to
configure absolute path to configuration.

--
Paul

Bogdan Glinskiy

unread,
Dec 16, 2014, 11:19:13 AM12/16/14
to zer...@googlegroups.com
Well, unfortunately it's expected. Zerogw was never designed with
embedding in mind. So zerogw closes listening socket, but doesn't walk
connected sockets, because just exiting process works for zerogw.
Presumably working websockets may even crash the process. Do you need
to restart zerogw itself without restarting process? I don't believe
it's possible without huge amount of work.

 
 Yes, i need to restart zerogw itself without restarting process... Well, from what side i should start? Should i modify zerogw sources?

 
Probably you changed current directory in the process. You can try to
configure absolute path to configuration.


Nope, as i said, my program doesn't change neither path nor configuration file. And i used kind of debug information about that during debugging my program. 
And i thing, this problem is caused  by the problem i described above.

--
Thanks for answers,
Bogdan Glinskiy

Paul Colomiets

unread,
Dec 16, 2014, 3:11:56 PM12/16/14
to zer...@googlegroups.com
Hi Bogdan,

On Tue, Dec 16, 2014 at 6:19 PM, Bogdan Glinskiy <fett...@gmail.com> wrote:
>> Well, unfortunately it's expected. Zerogw was never designed with
>> embedding in mind. So zerogw closes listening socket, but doesn't walk
>> connected sockets, because just exiting process works for zerogw.
>> Presumably working websockets may even crash the process. Do you need
>> to restart zerogw itself without restarting process? I don't believe
>> it's possible without huge amount of work.
>>
>
> Yes, i need to restart zerogw itself without restarting process... Well,
> from what side i should start? Should i modify zerogw sources?
>

First you need to patch libwebsite, to keep list of connections, and
close them on ws_socket_stop.

Then you need to check valgrinds output after you stop embedded
zerogw, to know whether all pieces of memory that zerogw had allocated
are free.

But I strongly advise you to consider either running zerogw in
subprocess, or do exec() system call to restart process in-place ,
instead of embedding

>
>>
>> Probably you changed current directory in the process. You can try to
>> configure absolute path to configuration.
>>
>
> Nope, as i said, my program doesn't change neither path nor configuration
> file. And i used kind of debug information about that during debugging my
> program.
> And i thing, this problem is caused by the problem i described above.
>

Try to run strace, and see which file is opened by zerogw. Probably
there is some garbage in memory instead of configuration file name.

--
Paul
Reply all
Reply to author
Forward
0 new messages