Commit 69cdeb69 authored by rswindell's avatar rswindell
Browse files

Created and used call_socket_open_callback() to track the sockets opened

via JS Socket->xpms_accept().
Also, use do_js_close() to eliminate some repeated code in js_socket.c.
parent bcaf47b5
......@@ -314,14 +314,7 @@ static void js_finalize_socket(JSContext *cx, JSObject *obj)
if((p=(js_socket_private_t*)JS_GetPrivate(cx,obj))==NULL)
return;
if(p->session != -1) {
cryptDestroySession(p->session);
p->session=-1;
}
if(p->external==FALSE && p->sock!=INVALID_SOCKET) {
close_socket(p->sock);
dbprintf(FALSE, p, "closed/deleted");
}
do_js_close(p);
if(p->hostname)
free(p->hostname);
......@@ -612,6 +605,7 @@ js_accept(JSContext *cx, uintN argc, jsval *arglist)
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
call_socket_open_callback(TRUE);
}
else {
if((new_socket=accept_socket(p->sock,&(p->remote_addr),&addrlen))==INVALID_SOCKET) {
......
......@@ -290,28 +290,34 @@ void sock_close_cb(SOCKET sock, void *cb_data)
su->socket_open(su->cbdata, FALSE);
}
void call_socket_open_callback(BOOL open)
{
if(startup!=NULL && startup->socket_open!=NULL)
startup->socket_open(startup->cbdata, open);
}
SOCKET open_socket(int type, const char* protocol)
{
SOCKET sock;
char error[256];
sock=socket(AF_INET, type, IPPROTO_IP);
if(sock!=INVALID_SOCKET && startup!=NULL && startup->socket_open!=NULL)
startup->socket_open(startup->cbdata,TRUE);
if(sock!=INVALID_SOCKET)
call_socket_open_callback(TRUE);
if(sock!=INVALID_SOCKET && set_socket_options(&scfg, sock, protocol, error, sizeof(error)))
lprintf(LOG_ERR,"%04d !ERROR %s",sock,error);
return(sock);
}
// Used by sbbs_t::ftp_put():
// Used by sbbs_t::ftp_put() and js_accept()
SOCKET accept_socket(SOCKET s, union xp_sockaddr* addr, socklen_t* addrlen)
{
SOCKET sock;
sock=accept(s,&addr->addr,addrlen);
if(sock!=INVALID_SOCKET && startup!=NULL && startup->socket_open!=NULL)
startup->socket_open(startup->cbdata,TRUE);
if(sock!=INVALID_SOCKET)
call_socket_open_callback(TRUE);
return(sock);
}
......@@ -325,8 +331,7 @@ int close_socket(SOCKET sock)
shutdown(sock,SHUT_RDWR); /* required on Unix */
result=closesocket(sock);
if(startup!=NULL && startup->socket_open!=NULL)
startup->socket_open(startup->cbdata,FALSE);
call_socket_open_callback(FALSE);
if(result!=0 && ERROR_VALUE!=ENOTSOCK)
lprintf(LOG_WARNING,"!ERROR %d closing socket %d",ERROR_VALUE,sock);
return(result);
......@@ -5244,8 +5249,7 @@ NO_SSH:
}
// Count the socket:
if(startup->socket_open!=NULL)
startup->socket_open(startup->cbdata, TRUE);
call_socket_open_callback(TRUE);
if(client_socket == INVALID_SOCKET) {
#if 0 /* is this necessary still? */
......
......@@ -1357,6 +1357,7 @@ char* prep_code(char *str, const char* prefix);
int lputs(int level, const char *); /* log output */
int lprintf(int level, const char *fmt, ...); /* log output */
int eprintf(int level, const char *fmt, ...); /* event log */
void call_socket_open_callback(BOOL open);
SOCKET open_socket(int type, const char* protocol);
SOCKET accept_socket(SOCKET s, union xp_sockaddr* addr, socklen_t* addrlen);
int close_socket(SOCKET);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment