pthread_mutex_t mutex; /**< resource control */
union {
struct {
- uint32_t id;
struct afb_ws *ws;
struct api_ws_event *events;
struct api_ws_memo *memos;
#define RETERR 2
#define RETRAW 3
+/******************* common usefull tools **********************************/
+
+/**
+ * translate a pointer to some integer
+ * @param ptr the pointer to translate
+ * @return an integer
+ */
+static inline uint32_t ptr2id(void *ptr)
+{
+ return (uint32_t)(((intptr_t)ptr) >> 6);
+}
+
/******************* websocket interface for client part **********************************/
static void api_ws_client_on_binary(void *closure, char *data, size_t size);
return -1;
}
- if (server)
+ if (server && path[0] != '@')
unlink(path);
fd = socket(AF_UNIX, SOCK_STREAM, 0);
memset(&addr, 0, sizeof addr);
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, path);
+ if (addr.sun_path[0] == '@')
+ addr.sun_path[0] = 0; /* implement abstract sockets */
if (server) {
rc = bind(fd, (struct sockaddr *) &addr, (socklen_t)(sizeof addr));
} else {
if (memo != NULL) {
afb_xreq_addref(xreq);
memo->xreq = xreq;
- do { memo->msgid = ++api->client.id; } while(api_ws_client_memo_search(api, memo->msgid) != NULL);
+ memo->msgid = ptr2id(memo);
+ while(api_ws_client_memo_search(api, memo->msgid) != NULL)
+ memo->msgid++;
memo->api = api;
memo->next = api->client.memos;
api->client.memos = memo;
sc->closure = cb_closure;
pthread_mutex_unlock(&client->mutex);
- sc->subcallid = (uint32_t)(((intptr_t)sc) >> 6);
+ sc->subcallid = ptr2id(sc);
do {
sc->subcallid++;
osc = client->subcalls;