4
#include "erl_driver.h"
10
static ErlDrvData example_drv_start(ErlDrvPort port, char *buff)
12
example_data* d = (example_data*)driver_alloc(sizeof(example_data));
17
static void example_drv_stop(ErlDrvData handle)
19
driver_free((char*)handle);
22
static void example_drv_output(ErlDrvData handle, char *buff, int bufflen)
24
example_data* d = (example_data*)handle;
25
char fn = buff[0], arg = buff[1], res;
31
driver_output(d->port, &res, 1);
34
ErlDrvEntry example_driver_entry = {
35
NULL, /* F_PTR init, N/A */
36
example_drv_start, /* L_PTR start, called when port is opened */
37
example_drv_stop, /* F_PTR stop, called when port is closed */
38
example_drv_output, /* F_PTR output, called when erlang has sent */
39
NULL, /* F_PTR ready_input, called when input descriptor ready */
40
NULL, /* F_PTR ready_output, called when output descriptor ready */
41
"example_drv", /* char *driver_name, the argument to open_port */
42
NULL, /* F_PTR finish, called when unloaded */
43
NULL, /* F_PTR control, port_command callback */
44
NULL, /* F_PTR timeout, reserved */
45
NULL /* F_PTR outputv, reserved */
48
DRIVER_INIT(example_drv) /* must match name in driver_entry */
50
return &example_driver_entry;