Skip to content

Commit

Permalink
erlang: clang-format for coherent indentation and coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxmaniac committed May 18, 2023
1 parent 5886f61 commit 4d856d4
Show file tree
Hide file tree
Showing 28 changed files with 3,769 additions and 3,732 deletions.
447 changes: 234 additions & 213 deletions src/modules/erlang/cnode.c

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions src/modules/erlang/cnode.h
Expand Up @@ -45,7 +45,7 @@ typedef struct cnode_handler_s
int (*handle_f)(handler_common_t *phandler_t);
int (*wait_tmo_f)(handler_common_t *phandler_t);
int (*destroy_f)(handler_common_t *phandler_t);
int sockfd; /* connection socket to remote erlang node */
int sockfd; /* connection socket to remote erlang node */
ei_cnode ec; /* erlang C node (actually it's kamailio node) */

/*
Expand Down Expand Up @@ -83,7 +83,7 @@ typedef struct csockfd_handler_s
int (*handle_f)(handler_common_t *phandler_t);
int (*wait_tmo_f)(handler_common_t *phandler_t);
int (*destroy_f)(handler_common_t *phandler_t);
int sockfd; /* its csockfd */
int sockfd; /* its csockfd */
ei_cnode ec; /* erlang C node (actually it's kamailio node) */
} csockfd_handler_t;

Expand All @@ -99,10 +99,12 @@ int handle_cnode(handler_common_t *phandler_t);
int wait_cnode_tmo(handler_common_t *phandler_t);
int destroy_cnode(handler_common_t *phandler_t);

int cnode_connect_to(cnode_handler_t *phandler, ei_cnode *ec, const str *nodename );
int cnode_connect_to(
cnode_handler_t *phandler, ei_cnode *ec, const str *nodename);
int enode_connect();

enum erl_handle_type {
enum erl_handle_type
{
ERL_EPMD_H = 1,
ERL_CNODE_H,
ERL_WORKER_H,
Expand Down
56 changes: 26 additions & 30 deletions src/modules/erlang/epmd.c
Expand Up @@ -44,8 +44,8 @@ int epmd_init(epmd_handler_t *epmd, str *alivename)
epmd->sockfd = erl_init_node(&epmd->ec, alivename, &cnode_host, &cookie);
epmd->handle_f = handle_epmd;
epmd->wait_tmo_f = NULL;
epmd->destroy_f = NULL;
epmd->new = NULL;
epmd->destroy_f = NULL;
epmd->new = NULL;

return epmd->sockfd;
}
Expand All @@ -56,7 +56,7 @@ int epmd_init(epmd_handler_t *epmd, str *alivename)
int handle_epmd(handler_common_t *phandler)
{
struct ip_addr ip;
struct sockaddr addr = { 0 };
struct sockaddr addr = {0};
struct sockaddr *paddr;
socklen_t addrlen = sizeof(struct sockaddr);
int port;
Expand All @@ -69,56 +69,54 @@ int handle_epmd(handler_common_t *phandler)
ErlConnect conn;

paddr = &addr;
me = (epmd_handler_t*) phandler;
me = (epmd_handler_t *)phandler;

if ((sockfd = ei_accept_tmo(&me->ec, me->sockfd, &conn, CONNECT_TIMEOUT))
if((sockfd = ei_accept_tmo(&me->ec, me->sockfd, &conn, CONNECT_TIMEOUT))
== ERL_ERROR) {
LM_ERR("error on accept connection: %s.\n", strerror(erl_errno));

if (erl_errno == ETIMEDOUT) {
if(erl_errno == ETIMEDOUT) {
return 0;
} else if (errno) {
} else if(errno) {
LM_ERR("socket error: %s\n", strerror(errno));
return -1;
} else {
/* if errno didn't get set, assume nothing *too much* horrible occurred */
LM_NOTICE("ignored error in ei_accept, probably: bad client version, "
LM_NOTICE(
"ignored error in ei_accept, probably: bad client version, "
"bad cookie or bad node name\n");
}
return 0;
}

/* get remote address info of connected socket */
if ((ai_error = getpeername(sockfd, paddr, &addrlen)))
{
LM_ERR("%s\n",strerror(errno));
}
else
{
sockaddr2ip_addr(&ip,paddr);
if((ai_error = getpeername(sockfd, paddr, &addrlen))) {
LM_ERR("%s\n", strerror(errno));
} else {
sockaddr2ip_addr(&ip, paddr);
port = sockaddr_port(paddr);

LM_DBG("connected from %s port %u\n", ip_addr2strz(&ip), port);
}

remotenode = (cnode_handler_t*)pkg_malloc(sizeof(cnode_handler_t));
if (!remotenode) {
remotenode = (cnode_handler_t *)pkg_malloc(sizeof(cnode_handler_t));
if(!remotenode) {
erl_close_socket(sockfd);
return -1;
}

/* tos */
on=IPTOS_LOWDELAY;
if (setsockopt(sockfd, IPPROTO_IP, IP_TOS, (void*)&on,sizeof(on)) ==-1) {
LM_WARN("setsockopt set tos failed: %s\n", strerror(errno));
/* continue since this is not critical */
on = IPTOS_LOWDELAY;
if(setsockopt(sockfd, IPPROTO_IP, IP_TOS, (void *)&on, sizeof(on)) == -1) {
LM_WARN("setsockopt set tos failed: %s\n", strerror(errno));
/* continue since this is not critical */
}

if (erl_set_nonblock(sockfd)){
if(erl_set_nonblock(sockfd)) {
LM_ERR("set non blocking socket failed\n");
}

memset((void*)remotenode,0,sizeof(cnode_handler_t));
memset((void *)remotenode, 0, sizeof(cnode_handler_t));

remotenode->handle_f = handle_cnode;
remotenode->wait_tmo_f = wait_cnode_tmo;
Expand All @@ -129,19 +127,17 @@ int handle_epmd(handler_common_t *phandler)
/* for #Pid */
remotenode->ec.self.num = sockfd;

if (ei_x_new(&remotenode->request))
{
LOG(L_ERR,"failed to allocate ei_x_buff: %s.\n", strerror(erl_errno));
if(ei_x_new(&remotenode->request)) {
LOG(L_ERR, "failed to allocate ei_x_buff: %s.\n", strerror(erl_errno));
return -1;
}

if (ei_x_new_with_version(&remotenode->response))
{
LOG(L_ERR,"failed to allocate ei_x_buff: %s.\n", strerror(erl_errno));
if(ei_x_new_with_version(&remotenode->response)) {
LOG(L_ERR, "failed to allocate ei_x_buff: %s.\n", strerror(erl_errno));
return -1;
}

phandler->new = (handler_common_t*)remotenode;
phandler->new = (handler_common_t *)remotenode;

/* activate node */
enode = remotenode;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/erlang/epmd.h
Expand Up @@ -50,7 +50,7 @@ typedef struct epmd_handler_s
int (*handle_f)(handler_common_t *handler);
int (*wait_tmo_f)(handler_common_t *handler);
int (*destroy_f)(handler_common_t *handler);
int sockfd; /* socket to epmd */
int sockfd; /* socket to epmd */
ei_cnode ec; /* erlang C node (actually it's me) */

} epmd_handler_t;
Expand Down

0 comments on commit 4d856d4

Please sign in to comment.