Re: How to study mongrel2's source code?
- From:
- Tang Daogang
- Date:
- 2011-09-25 @ 03:36
Oh, great.
Dalton,
I think your hot heart will bring lots of hackers into mongrel2. And this
will make mongrel2 better.
Thank you one million.
On Saturday, September 24, 2011, Dalton Barreto <daltonmatos@gmail.com>
wrote:
> 2011/9/19 Tang Daogang <daogangtang@gmail.com>:
>> hi,
>>
>> I want to do some studies in Mongrel2's source code, and want to help to
>> promote its stability. But I don't know how to do first, if someone
knows,
>> or has some researching materials, can you share it with me?
>>
>
> Hello,
>
> Firstly, sorry for the late reply. Your email is in my inbox for some
> days now.. but anyway, better late than never. =)
> I don't think there is a "right" answer for your question, so what I
> will try to do is just describe how I managed to study
> mongrel2 source code and then became able to contribute fisrtly with
> very trivial patches (small fixes in test cases, for
> example) and some time later I was already contributing with
> non-trivial patches (support for large files, help modeling
> the filter infra-structure, etc).
>
>
> So the first thing I did was get a good tool to navigate through the
> source-code. At that time I used Eclipse with C/C++
> plugin, this helped me *a lot* because I was always one "ctrl+click"
> away from any function, so it was very easy to find out
> wich source file contained each set of functions.
>
> But with time you realize how mongrel2 source code is structured and
> just won't need the "ctrl+click" any more. For
> example take the connection.c file, line 173. There we have this line of
code:
>
> payload = Request_to_tnetstring(conn->req, handler->send_ident,
> IOBuf_fd(conn->iob), body, content_len);
>
> So, where is "Request_to_tnetstring" function? The functions are
> prefixed with the name of the source file where they are,
> in this example we could find the function on src/request.c line 358.
> So this is a good way to have an overall view about
> the code structure.
>
>
> Other than this there are key points hat are worth knowing:
>
> All starts at src/mongrel2.c in "void taskmain()" function. Here
> mongrel2 loads the server you asked for on the command
> line, registers the control port, adicional tasks (like the task that
> kills timed out connections), etc. Note that mongrel2 does
> not have the traditional int main() entry point, this is because it
> uses libtask, that provides the real "int main()".
>
> Anoter important point is the call of "Server_start(SERVER)" (guess in
> what file this function is? =)). Here we enter the
> main loop for this server that was just started. Inside this function
> the code calls "Connection_create()" for each new
> connection that is accepts, and then calls "Connection_accept()"
> passing that new connection.
>
> Connection_accept() registers this new connection e then creates a new
> "task" that is implemented by the
> "Connection_task()" function. Here is where all the magic happens!
> Here in Connection_task we have mongrel2 state
> machine in action. The State_exec() executes the current event and
> returns the next to be executed. If you try to read the
> code of src/state.c you will see that is a bit difficult to
> understand, that's because mongrel2 state machine is built with an
> external tool, named ragel [1], so you will need to read the docs to
> understand it better.
>
>
> Well, maybe this will help you start! =) I'm really sorry for this
> huge mail but I saw no other way to explain you what I did to
> learn the mongrel2 source-code.
>
> I think you can digest it in parts and then, at the end, you will feel
> much more confortable with the code base.
>
> That's it! Go hack! And remember, valgrind is your friend! Don't stop
> on your first segmentation fault, there will be many
> more! =)
>
> Happy hacking!
>
> [1] http://www.complang.org/ragel/
>
> --
> Dalton Barreto
> http://daltonmatos.com
>
--
Nothing is impossible.
Re: [mongrel2] Re: How to study mongrel2's source code?
- From:
- Dalton Barreto
- Date:
- 2011-09-25 @ 22:53
2011/9/25 Tang Daogang <daogangtang@gmail.com>:
> Oh, great.
>
> Dalton,
> I think your hot heart will bring lots of hackers into mongrel2. And this
> will make mongrel2 better.
>
> Thank you one million.
That's awesome!!! I'm glad it helped you!
If you have any other question about the source code, don't hesitate
to post it here.
--
Dalton Barreto
http://daltonmatos.com
How to study mongrel2's source code?
- From:
- Tang Daogang
- Date:
- 2011-09-25 @ 03:37
Oh, great.
Dalton,
I think your hot heart will bring lots of hackers into mongrel2. And this
will make mongrel2 better.
Thank you one million.
On Saturday, September 24, 2011, Dalton Barreto <daltonmatos@gmail.com>
wrote:
> 2011/9/19 Tang Daogang <daogangtang@gmail.com>:
>> hi,
>>
>> I want to do some studies in Mongrel2's source code, and want to help to
>> promote its stability. But I don't know how to do first, if someone
knows,
>> or has some researching materials, can you share it with me?
>>
>
> Hello,
>
> Firstly, sorry for the late reply. Your email is in my inbox for some
> days now.. but anyway, better late than never. =)
> I don't think there is a "right" answer for your question, so what I
> will try to do is just describe how I managed to study
> mongrel2 source code and then became able to contribute fisrtly with
> very trivial patches (small fixes in test cases, for
> example) and some time later I was already contributing with
> non-trivial patches (support for large files, help modeling
> the filter infra-structure, etc).
>
>
> So the first thing I did was get a good tool to navigate through the
> source-code. At that time I used Eclipse with C/C++
> plugin, this helped me *a lot* because I was always one "ctrl+click"
> away from any function, so it was very easy to find out
> wich source file contained each set of functions.
>
> But with time you realize how mongrel2 source code is structured and
> just won't need the "ctrl+click" any more. For
> example take the connection.c file, line 173. There we have this line of
code:
>
> payload = Request_to_tnetstring(conn->req, handler->send_ident,
> IOBuf_fd(conn->iob), body, content_len);
>
> So, where is "Request_to_tnetstring" function? The functions are
> prefixed with the name of the source file where they are,
> in this example we could find the function on src/request.c line 358.
> So this is a good way to have an overall view about
> the code structure.
>
>
> Other than this there are key points hat are worth knowing:
>
> All starts at src/mongrel2.c in "void taskmain()" function. Here
> mongrel2 loads the server you asked for on the command
> line, registers the control port, adicional tasks (like the task that
> kills timed out connections), etc. Note that mongrel2 does
> not have the traditional int main() entry point, this is because it
> uses libtask, that provides the real "int main()".
>
> Anoter important point is the call of "Server_start(SERVER)" (guess in
> what file this function is? =)). Here we enter the
> main loop for this server that was just started. Inside this function
> the code calls "Connection_create()" for each new
> connection that is accepts, and then calls "Connection_accept()"
> passing that new connection.
>
> Connection_accept() registers this new connection e then creates a new
> "task" that is implemented by the
> "Connection_task()" function. Here is where all the magic happens!
> Here in Connection_task we have mongrel2 state
> machine in action. The State_exec() executes the current event and
> returns the next to be executed. If you try to read the
> code of src/state.c you will see that is a bit difficult to
> understand, that's because mongrel2 state machine is built with an
> external tool, named ragel [1], so you will need to read the docs to
> understand it better.
>
>
> Well, maybe this will help you start! =) I'm really sorry for this
> huge mail but I saw no other way to explain you what I did to
> learn the mongrel2 source-code.
>
> I think you can digest it in parts and then, at the end, you will feel
> much more confortable with the code base.
>
> That's it! Go hack! And remember, valgrind is your friend! Don't stop
> on your first segmentation fault, there will be many
> more! =)
>
> Happy hacking!
>
> [1] http://www.complang.org/ragel/
>
> --
> Dalton Barreto
> http://daltonmatos.com
>
--
Nothing is impossible.
--
Nothing is impossible.