Skip to content

Commit

Permalink
Added ability to query status and shutdown daemon over local network …
Browse files Browse the repository at this point in the history
…port

For use in raveloxmidibox.

See https://github.com/ravelox/raveloxmidibox for that projectwq
  • Loading branch information
Dave Kelly committed Oct 11, 2018
1 parent a75267d commit 9124caa
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
21 changes: 21 additions & 0 deletions python/send_quit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/python

import socket
import struct

# Request status
bytes = struct.pack( "B4s", 0xaa, "QUIT" )
print bytes

s = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
s.connect( ("localhost", 5006 ) )
s.sendall( bytes )

data = ''
while True:
data = s.recv(2)
if data:
break

print repr(data)
s.close()
21 changes: 21 additions & 0 deletions python/status_send.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/python

import socket
import struct

# Request status
bytes = struct.pack( "B4s", 0xaa, "STAT" )
print bytes

s = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
s.connect( ("localhost", 5006 ) )
s.sendall( bytes )

data = ''
while True:
data = s.recv(2)
if data:
break

print repr(data)
s.close()
23 changes: 23 additions & 0 deletions raveloxmidi/src/net_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pthread_t alsa_listener_thread;
int socket_timeout = 0;
int pipe_fd[2];

static void set_shutdown_lock( int i );

void net_socket_add( int new_socket )
{
int *new_socket_list = NULL;
Expand Down Expand Up @@ -245,6 +247,27 @@ int net_socket_read( int fd )
}

net_applemidi_cmd_destroy( &command );
} else if( (packet[0]==0xaa) && (recv_len == 5) && ( strncmp( &(packet[1]),"STAT",4)==0) )
// Heartbeat request
{
unsigned char *buffer="OK";
size_t bytes_written = 0;
pthread_mutex_lock( &socket_mutex );
bytes_written = sendto( fd, buffer, strlen(buffer), 0 , (struct sockaddr *)&from_addr, from_len);
pthread_mutex_unlock( &socket_mutex );
logging_printf(LOGGING_DEBUG, "net_socket_read: Heartbeat request. Response written: %u\n", bytes_written);

} else if( (packet[0]==0xaa) && (recv_len == 5) && ( strncmp( &(packet[1]),"QUIT",4)==0) )
// Shutdown request
{
unsigned char *buffer="QT";
size_t bytes_written = 0;
pthread_mutex_lock( &socket_mutex );
bytes_written = sendto( fd, buffer, strlen(buffer), 0 , (struct sockaddr *)&from_addr, from_len);
pthread_mutex_unlock( &socket_mutex );
logging_printf(LOGGING_DEBUG, "net_socket_read: Shutdown request. Response written: %u\n", bytes_written);
logging_printf(LOGGING_NORMAL, "Shutdown request received on local socket\n");
set_shutdown_lock(1);
#ifdef HAVE_ALSA
} else if( (packet[0]==0xaa) || (fd==RAVELOXMIDI_ALSA_INPUT) )
#else
Expand Down

0 comments on commit 9124caa

Please sign in to comment.