static int _applemidi_read_fds( void * drv, int nfds, fd_set * readfds ) { struct MIDIDriverAppleMIDI * driver = drv; int fd, result = 0; if( nfds <= 0 ) return 0; if( FD_ISSET( driver->control_socket, readfds ) ) { fd = driver->control_socket; if( _test_applemidi( fd ) == 0 ) { if( _applemidi_recv_command( driver, fd, &(driver->command) ) == 0 ) { result += _applemidi_respond( driver, fd, &(driver->command) ); } } } if( FD_ISSET( driver->rtp_socket, readfds ) ) { fd = driver->rtp_socket; if( _test_applemidi( fd ) == 0 ) { if( _applemidi_recv_command( driver, fd, &(driver->command) ) == 0 ) { result += _applemidi_respond( driver, fd, &(driver->command) ); } } else { result += _applemidi_receive_rtpmidi( driver ); } } _applemidi_update_runloop_source( driver ); return result; }
static void _socket_callback(struct sock *sk) { struct MIDIDriverAppleMIDI *driver = raspi; // should NOT be global int len = 0; int length; u16 *l; struct sk_buff *skb; len = skb_queue_len(&sk->sk_receive_queue); while (len > 0) { skb = skb_dequeue(&sk->sk_receive_queue); l = (u16 *)(skb->data + 4); length = ntohs(*l); pr_debug("message length %d bytes\n", length); if (length >= (8 + 4)) { if (_test_applemidi((u16 *)(skb->data + 8), length - 8) == 0) { pr_debug("is applemidi message\n"); // test if possible now: if (spin_trylock(&(driver->lock))) { pr_debug("allowed (lock not taken)\n"); if (_applemidi_recv_command( driver, skb, &(driver->command)) == 0) { pr_debug("reply to command\n"); _applemidi_respond( driver, sk, &(driver->command)); } spin_unlock(&(driver->lock)); } else { pr_warn("dropped packet because of " "sending note\n"); } } else if (driver->rtp_socket->sk == sk) { // handle incomming midi //_applemidi_receive_rtpmidi( driver ); } } len--; kfree_skb(skb); } }