-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bundle for making HTTP GETrequests #369
Bundle for making HTTP GETrequests #369
Conversation
Using network programming in C, we wrap the functionality in an active Encore class.
A rudimetary class Response with a single field for the raw respose is used as the resturn type of Response.GET Using the website 'www.httpbin.org' we test responses of statuses 200, 300, 400 and 500.
|
||
// Allocate the buffer and result | ||
int result_size = buffer_size + 1; | ||
char *buffer = malloc(buffer_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be allocated on the stack? Now it looks like this memory will leak!
@pengstrom: See #373 for methods that might be useful for your tests!
|
As a side note, the PonyRT has support for Async IO. I read an article where someone mentioned that it is pretty good (I cannot find the article now...) |
Unlike encore_alloc, encore_realloc doesn't zero the memory on resizing (into larger) and you have to do that manually using memset.
I've updated my branch with your kind suggestions. I'm now using the native conversion functions for strings, and the memory is (hopefully) garbage collected. In addition, a function |
#include <netinet/in.h> /* struct sockaddr_in, struct sockaddr */ | ||
#include <netdb.h> /* struct hostent, gethostbyname */ | ||
|
||
#include <encore.h> /* encore_alloc, encore_realloc */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file compiles for me even if I remove stdio.h
, stdlib.h
, string.h
and encore.h
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's included elsewhere up the chain. But isn't it good to be explicit about dependencies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't hurt having them there I guess. At least encore.h
seems redundant though, as it must be present for the Encore code to compile. I have no strong feelings about removing or keeping them.
Only minor things left, then I think this is mergable! |
Also used native string functions for concatenating stings.
I'm in favour of merging this now! Will do so tomorrow if no one objects. |
I don't think it's needed for the identical comment to appear in both header and source file. There are trailing space in For the embedded C code,
It's unclear to me why I didn't get any error on running |
@albertnetymk: I'm getting errors if I increase the number of iterations in |
@EliasC I can't reproduce the failure with |
@albertnetymk: I see the crash with |
@EliasC I can confirm it on my box. Looks like a data-race caused bug from the error msg in gdb. |
Also, it goes away with |
The crashing is concluded to be caused by misusing obsolete |
Thanks for your feedback!
I'm only losing precision with the functions For the |
The comment is kept in the header
True, but it would be surprising to see that the program starts to behave strangely with a larger buffer size. The benefit of using a macro for buffer size is that the rest of the program can be kept intact.
Think so. |
@albertnetymk |
Looks good.
Can be merged as it is. I would suggest to squash it into one commit on merging, unless the author of this PR plans to do a rebase to tidy the history a bit. |
Go ahead and squash! |
There were no Encore bindings to the C functions for network programming. I have written a convenient wrapper around some C code for making http requests able to receive an arbitrary sized response.
Testing is a little weird since we don't have a development web server of our own. Instead, I request
www.httpbin.org
to test different return codes.To make a request, import
Request
and use theGET
function to make a requestI have only implemented the GET functionality, and the response object only contains the raw request. I plan on enabling more methods and convenient getters in the response object.