Skip to content

Commit

Permalink
pre-release tweaks/fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vividsnow committed Aug 22, 2024
1 parent 0966f48 commit 6cb46b6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 29 deletions.
9 changes: 9 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
Revision history for Perl extension Feersum

1.500 Tue Aug 20 18:10:55 2024 -0200
Features:
- native interface: access specific parts of request
- http/1.1 keepalive support
- http/1.1 date header
- defer accept, accept4
Backward incompatibly:
- remove adobe flash policy support

1.410 Sat Dec 5 14:32:22 2020 +0800
Features
- Add unix domain socket support (vividsnow++)
Expand Down
48 changes: 23 additions & 25 deletions Feersum.xs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define PERL_NO_GET_CONTEXT
#include "EVAPI.h"
#define PERL_NO_GET_CONTEXT
#include "ppport.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
Expand All @@ -10,9 +11,7 @@
#include <netinet/tcp.h>
#include <sys/uio.h>
#include <time.h>

#include "ppport.h"

#include "picohttpparser-git/picohttpparser.c"

///////////////////////////////////////////////////////////////
// "Compile Time Options" - See Feersum.pm POD for information
Expand All @@ -27,8 +26,8 @@
#define READ_TIMEOUT 5.0

#define AUTOCORK_WRITES 1
#define KEEPALIVE_CONNECTION false
#define DATE_HEADER true
#define KEEPALIVE_CONNECTION 0
#define DATE_HEADER 1

// may be lower for your platform (e.g. Solaris is 16). See POD.
#define FEERSUM_IOMATRIX_SIZE 64
Expand All @@ -40,8 +39,6 @@
#endif

///////////////////////////////////////////////////////////////


#ifdef __GNUC__
# define likely(x) __builtin_expect(!!(x), 1)
# define unlikely(x) __builtin_expect(!!(x), 0)
Expand Down Expand Up @@ -127,7 +124,6 @@
#define trace3(...)
#endif

#include "picohttpparser-git/picohttpparser.c"
#include "rinq.c"

// Check FEERSUM_IOMATRIX_SIZE against what's actually usable on this
Expand Down Expand Up @@ -217,10 +213,10 @@ struct feer_conn {
enum feer_receive_state receiving;
bool is_keepalive;

int in_callback;
int is_http11:1;
int poll_write_cb_is_io_handle:1;
int auto_cl:1;
unsigned int in_callback;
unsigned int is_http11:1;
unsigned int poll_write_cb_is_io_handle:1;
unsigned int auto_cl:1;
};

enum feer_header_norm_style {
Expand Down Expand Up @@ -335,20 +331,20 @@ static const char *const MONTHS[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
static char DATE_BUF[DATE_HEADER_LENGTH+1] = "Date: The, 01 Jan 1970 00:00:00 GMT\015\012";
static time_t LAST_GENERATED_TIME = 0;

static inline void uint_to_str(unsigned int value, char *str) {
static INLINE_UNLESS_DEBUG void uint_to_str(unsigned int value, char *str) {
str[0] = (value / 10) + '0';
str[1] = (value % 10) + '0';
}

static inline void uint_to_str_4digits(unsigned int value, char *str) {
static INLINE_UNLESS_DEBUG void uint_to_str_4digits(unsigned int value, char *str) {
str[0] = (value / 1000) + '0';
str[1] = (value / 100) % 10 + '0';
str[2] = (value / 10) % 10 + '0';
str[3] = value % 10 + '0';
}

INLINE_UNLESS_DEBUG
void generate_date_header(void) {
static void generate_date_header(void) {
time_t now = time(NULL);
if (now == LAST_GENERATED_TIME) return;

Expand Down Expand Up @@ -675,7 +671,7 @@ new_feer_conn (EV_P_ int conn_fd, struct sockaddr *sa)
c->sa = sa;
c->responding = RESPOND_NOT_STARTED;
c->receiving = RECEIVE_HEADERS;
c->is_keepalive = false;
c->is_keepalive = 0;

ev_io_init(&c->read_ev_io, try_conn_read, conn_fd, EV_READ);
c->read_ev_io.data = (void *)c;
Expand Down Expand Up @@ -958,7 +954,7 @@ try_write_again_immediately:
goto try_write_finished;
}

bool consume = true;
bool consume = 1;
for (i = m->offset; i < m->count && consume; i++) {
struct iovec *v = &m->iov[i];
if (unlikely(v->iov_len > wrote)) {
Expand All @@ -967,7 +963,7 @@ try_write_again_immediately:
v->iov_base += wrote;
v->iov_len -= wrote;
// don't consume any more:
consume = false;
consume = 0;
}
else {
trace3("consume vector %d base=%p len=%"Sz_uf" sv=%p\n",
Expand Down Expand Up @@ -1269,15 +1265,17 @@ accept_cb (EV_P_ ev_io *w, int revents)
struct feer_conn *c = new_feer_conn(EV_A,fd,sa);
#ifdef TCP_DEFER_ACCEPT
try_conn_read(EV_A, &c->read_ev_io, EV_READ);
assert(SvREFCNT(c->self) <= 3);
#else
if (is_tcp) {
start_read_watcher(c);
restart_read_timer(c);
assert(SvREFCNT(c->self) == 3);
} else {
try_conn_read(EV_A, &c->read_ev_io, EV_READ);
assert(SvREFCNT(c->self) <= 3);
}
#endif
assert(SvREFCNT(c->self) == 3);
SvREFCNT_dec(c->self);
}
}
Expand Down Expand Up @@ -1305,7 +1303,7 @@ process_request_headers (struct feer_conn *c, int body_offset)
trace("processing headers %d minor_version=%d\n",c->fd,req->minor_version);
bool body_is_required;
bool next_req_follows = 0;
bool got_content_length = false;
bool got_content_length = 0;

c->is_http11 = (req->minor_version == 1);
c->is_keepalive = is_keepalive && c->is_http11;
Expand Down Expand Up @@ -1378,7 +1376,7 @@ process_request_headers (struct feer_conn *c, int body_offset)
goto got_bad_request;
}
else
got_content_length = true;
got_content_length = 1;
}
else {
err_code = 400;
Expand All @@ -1393,15 +1391,15 @@ process_request_headers (struct feer_conn *c, int body_offset)
&& likely(str_case_eq("close", 5, hdr->value, hdr->value_len))
&& c->is_keepalive)
{
c->is_keepalive = false;
c->is_keepalive = 0;
trace("setting conn %d to close after response\n", c->fd);
}
else if (
likely(!c->is_http11)
&& likely(str_case_eq("keep-alive", 10, hdr->value, hdr->value_len))
&& !c->is_keepalive)
{
c->is_keepalive = true;
c->is_keepalive = 1;
trace("setting conn %d to keep after response\n", c->fd);
}
}
Expand Down Expand Up @@ -1644,7 +1642,7 @@ feersum_set_path_and_query(pTHX_ struct feer_req *r)
qpos++;
r->query = newSVpvn(qpos, r->uri_len - (qpos - r->uri));
} else {
r->path = feersum_env_uri(r);
r->path = feersum_env_uri(aTHX_ r);
r->query = newSVpvs("");
}
uri_decode_sv(r->path);
Expand Down
2 changes: 1 addition & 1 deletion lib/Feersum.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use warnings;
use EV ();
use Carp ();

our $VERSION = '1.410';
our $VERSION = '1.500';

require Feersum::Connection;
require Feersum::Connection::Handle;
Expand Down
2 changes: 1 addition & 1 deletion lib/Feersum/Runner.pm
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ sub _fork_another {
EV::break(EV::BREAK_ALL()) unless $self->{_n_kids};
return;
}
$self->_fork_another();
$self->_fork_another($slot);
};
return;
}
Expand Down
2 changes: 1 addition & 1 deletion t/07-graceful-shutdown.t
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ sub client {
},
sub {
my ($body, $headers) = @_;
is $headers->{Status}, 200, "$cnum got 200";
is($headers->{Status}, 200, "$cnum got 200") or diag($headers->{Reason});
is $headers->{'transfer-encoding'}, "chunked", "$cnum got chunked!";
is $body, "So graceful!\n", "$cnum got body";
$cv->end;
Expand Down
4 changes: 3 additions & 1 deletion t/13-pre-fork.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sub simple_get {
name => "client $n",
sub {
my ($body,$headers) = @_;
is $headers->{Status}, 200, "client $n: http success";
is($headers->{Status}, 200, "client $n: http success") or diag($headers->{Reason});
like $body, qr/^Hello customer number 0x[0-9a-f]+$/, "client $n: looks good";
$cv->end;
undef $cli;
Expand All @@ -46,6 +46,8 @@ if (!$pid) {
POSIX::exit(0);
}

select undef, undef, undef, 0.25; # sleep a bit to give the server time to start

$cv = AE::cv;
simple_get($port, $_) for (1..CLIENTS);
$cv->recv;
Expand Down

0 comments on commit 6cb46b6

Please sign in to comment.