From c66032630f0e4fc3f4b59413a12f9ab35be958be Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 19 Jul 2018 16:29:32 +0200 Subject: Reconnect when connection is lost Signed-off-by: Florian Pritz --- lib/App/ImapNotify/Socket/SSL.pm | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'lib/App/ImapNotify/Socket/SSL.pm') diff --git a/lib/App/ImapNotify/Socket/SSL.pm b/lib/App/ImapNotify/Socket/SSL.pm index 18d7ffa..2654cdc 100644 --- a/lib/App/ImapNotify/Socket/SSL.pm +++ b/lib/App/ImapNotify/Socket/SSL.pm @@ -8,24 +8,26 @@ use Function::Parameters; use IO::Socket::SSL; use Log::Any qw($log); -method new($class: $host, $port, $deps = {}) { - $deps->{sock} //= IO::Socket::SSL->new("$host:$port"); - return $class->new_no_defaults($deps); -} - -method new_no_defaults($class: $deps = {}) { +method new($class: $host, $port) { my $self = {}; + $self->{config} = { + host => $host, + port => $port, + }; bless $self, $class; - $self->{deps} = $deps; return $self; } +method reconnect() { + $self->{sock} = IO::Socket::SSL->new("$self->{config}->{host}:$self->{config}->{port}"); +} + method readline() { - return CORE::readline $self->{deps}->{sock}; + return CORE::readline $self->{sock}; } method writeline($line) { - print {$self->{deps}->{sock}} $line; + print {$self->{sock}} $line; } -- cgit v1.2.3-24-g4f1b