Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

refactor open call to enable the OTP-8623 receive optimization #7

Open
wants to merge 1 commit into from

2 participants

@vinoski

Refactored the handling of the open call and the driver's handling of the
port_control call to enable the OTP-8623 receive optimization.

@vinoski vinoski refactor open call to enable the OTP-8623 receive optimization
Refactored the handling of the open call and the driver's handling of the
port_control call to enable the OTP-8623 receive optimization.
c34b18a
@okeuday

No messages are being sent from the port driver right now, right? Isn't this patch now invalid?

@vinoski

Yes @okeuday I believe you're correct; this is no longer needed because commit 28e26bc reworked the relevant code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 24, 2013
  1. @vinoski

    refactor open call to enable the OTP-8623 receive optimization

    vinoski authored
    Refactored the handling of the open call and the driver's handling of the
    port_control call to enable the OTP-8623 receive optimization.
This page is out of date. Refresh to see the latest.
Showing with 26 additions and 33 deletions.
  1. +9 −15 c_src/syslog_drv.c
  2. +17 −18 src/syslog.erl
View
24 c_src/syslog_drv.c
@@ -51,17 +51,6 @@ struct syslogdrv {
typedef struct syslogdrv syslogdrv_t;
-static ErlDrvSSizeT encode_error(char* buf, char* error) {
- int index = 0;
- if (ei_encode_version(buf, &index) ||
- ei_encode_tuple_header(buf, &index, 2) ||
- ei_encode_atom(buf, &index, "error") ||
- ei_encode_atom(buf, &index, error)) {
- return (ErlDrvSSizeT)ERL_DRV_ERROR_GENERAL;
- }
- return index+1;
-}
-
static ErlDrvData syslogdrv_start(ErlDrvPort port, char *buf)
{
syslogdrv_t* d = (syslogdrv_t*)driver_alloc(sizeof(syslogdrv_t));
@@ -110,7 +99,7 @@ static ErlDrvSSizeT syslogdrv_control(ErlDrvData handle, unsigned int command,
}
if (ei_decode_version(buf, &index, &version)) {
- return encode_error(*rbuf, "badver");
+ return (ErlDrvSSizeT)ERL_DRV_ERROR_BADARG;
}
if (ei_decode_tuple_header(buf, &index, &arity) || arity != 4) {
return (ErlDrvSSizeT)ERL_DRV_ERROR_BADARG;
@@ -124,11 +113,13 @@ static ErlDrvSSizeT syslogdrv_control(ErlDrvData handle, unsigned int command,
syslogdrv_t* nd = (syslogdrv_t*)driver_alloc(sizeof(syslogdrv_t));
if (nd == NULL) {
- return encode_error(*rbuf, "enomem");
+ errno = ENOMEM;
+ return (ErlDrvSSizeT)ERL_DRV_ERROR_ERRNO;
}
nd->ident = driver_alloc(size+1);
if (nd->ident == NULL) {
- return encode_error(*rbuf, "enomem");
+ errno = ENOMEM;
+ return (ErlDrvSSizeT)ERL_DRV_ERROR_ERRNO;
}
if (ei_decode_string(buf, &index, nd->ident)) {
driver_free(nd->ident);
@@ -153,7 +144,10 @@ static ErlDrvSSizeT syslogdrv_control(ErlDrvData handle, unsigned int command,
}
ref = driver_alloc_binary(size);
if (ref == NULL) {
- return encode_error(*rbuf, "enomem");
+ driver_free(nd->ident);
+ driver_free(nd);
+ errno = ENOMEM;
+ return (ErlDrvSSizeT)ERL_DRV_ERROR_ERRNO;
}
if (ei_decode_binary(buf, &index, ref->orig_bytes, &len)) {
driver_free_binary(ref);
View
35 src/syslog.erl
@@ -128,24 +128,23 @@ init([]) ->
end.
handle_call({open, Ident, Logopt, Facility}, {Pid,_}, #state{port = Port} = State) ->
- Ref = make_ref(),
- Args = term_to_binary({Ident, Logopt, Facility, term_to_binary(Ref)}),
- Reply = try erlang:port_control(Port, ?SYSLOGDRV_OPEN, Args) of
- <<>> ->
- receive
- {Ref, {ok, Log}=Result} ->
- erlang:port_connect(Log, Pid),
- unlink(Log),
- Result;
- {Ref, Result} ->
- Result
- end;
- BinError ->
- binary_to_term(BinError)
- catch
- _:Reason ->
- {error, Reason}
- end,
+ Reply =
+ try
+ Ref = make_ref(),
+ Args = term_to_binary({Ident, Logopt, Facility, term_to_binary(Ref)}),
+ erlang:port_control(Port, ?SYSLOGDRV_OPEN, Args),
+ receive
+ {Ref, {ok, Log}=Result} ->
+ erlang:port_connect(Log, Pid),
+ unlink(Log),
+ Result;
+ {Ref, Result} ->
+ Result
+ end
+ catch
+ _:Reason ->
+ {error, Reason}
+ end,
{reply, Reply, State};
handle_call(_Msg, _From, State) ->
{reply, ok, State}.
Something went wrong with that request. Please try again.