shlist

share and manage lists between multiple people
Log | Files | Refs

commit f60cfdb5914487b55741a5cb4184da36e0c81c38
parent c1c49c779bbb0c39024622fe5974fe2e5cd7fd6b
Author: Kyle Milz <kyle@0x30.net>
Date:   Sat, 27 Feb 2016 12:29:40 -0700

server: fold testd.pl into SL.pm

- we'll throw a class wrapper around it for easy use

Diffstat:
Mserver/SL.pm | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Dserver/testd.pl | 44--------------------------------------------
2 files changed, 51 insertions(+), 44 deletions(-)

diff --git a/server/SL.pm b/server/SL.pm @@ -258,3 +258,54 @@ sub msg_str { } 1; + +package SL::Notify; +use strict; + +use IO::Socket::UNIX; +use JSON::XS; + +sub new { + my $class = shift; + + my $self = {}; + bless ($self, $class); + + $self->{socket_path} = "../testd.socket"; + + my $server = IO::Socket::UNIX->new( + Type => SOCK_STREAM(), + Local => $self->{socket_path}, + Listen => 1, + ); + die "$self->{socket_path}: couldn't create socket: $!\n" unless ($server); + + while (my $client = $server->accept()) { + $client->read(my $data, 4096); + my $notify = decode_json($data); + + my $num_devices = @{ $notify->{devices} }; + next if ($num_devices == 0); + + print "testd: message type '$notify->{msg_type}'\n"; + # print "testd: payload is '" . Dumper($notify->{payload}) . "'\n"; + + for (@{ $notify->{devices} }) { + #print Dumper($_); + my ($os, $push_token) = @$_; + print "testd: sending to '$push_token' os '$os'\n"; + } + } + + return $self; +} + +sub DESTROY { + my $self = shift; + + unlink $self->{socket_path}; + #kill 'TERM', $self->{pid}; + #waitpid( $self->{pid}, 0 ); +} + +1; diff --git a/server/testd.pl b/server/testd.pl @@ -1,44 +0,0 @@ -#!/usr/bin/perl -use warnings; -use strict; -$| = 1; - -use Data::Dumper; -use IO::Socket::UNIX; -use JSON::XS; - -my $socket_path = "../testd.socket"; - -my $server = IO::Socket::UNIX->new( - Type => SOCK_STREAM(), - Local => $socket_path, - Listen => 1, -); -unless ($server) { - print "error: couldn't create socket: $!\n"; - exit 1; -} - -$SIG{INT} = \&unlink_socket; -$SIG{TERM} = \&unlink_socket; - -sub unlink_socket { - unlink $socket_path; -} - -while (my $client = $server->accept()) { - $client->read(my $data, 4096); - my $notify = decode_json($data); - - my $num_devices = @{ $notify->{devices} }; - next if ($num_devices == 0); - - print "testd: message type '$notify->{msg_type}'\n"; - # print "testd: payload is '" . Dumper($notify->{payload}) . "'\n"; - - for (@{ $notify->{devices} }) { - #print Dumper($_); - my ($os, $push_token) = @$_; - print "testd: sending to '$push_token' os '$os'\n"; - } -}