[erlang-questions] asynchronous driver, ready_input
Dennis Novikov
dennis.novikov@REDACTED
Thu Nov 20 17:53:02 CET 2008
Hi, all.
Does ready_input callback of asynchronous erlang driver have to be
thread-safe?
typedef struct {
ErlDrvPort port;
int fd;
char *rb; // result buffer
} drv_data;
I am allocating memory buffer in start callback like this
static ErlDrvData drv_start(ErlDrvPort port, char *buff)
{
drv_data* d = (drv_data*)driver_alloc(sizeof(drv_data);
d->port = port;
d->rb = (char*) driver_alloc(BUF_SZ);
set_port_control_flags(port, PORT_CONTROL_FLAG_BINARY);
driver_select(d->port, (ErlDrvEvent)d->fd, DO_READ, 1);
}
And in ready_input callback:
static void data_ready(ErlDrvData handle, ErlDrvEvent evt)
{
drv_data *d = (drv_data*)handle;
char *rbuf = d->rb;
int len = get_len();
put_some_data_into(rbuf); //
// Is this safe?
driver_output(d->port, rbuf, len); //
}
The code above is simplified. Be it real I would use
driver_output_binary(). If I understand correctly, that happens
behind the scene in driver_output() call, so I should be safe.
Am I?
--
Regards,
Dennis
More information about the erlang-questions
mailing list