mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 09:21:49 -05:00
Improve error handling for linux support (Permission denied on socket creation)
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@70 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
d1dadc1eeb
commit
de0f622378
@ -15,18 +15,14 @@ public abstract class AbstractServer extends Thread {
|
||||
* Create a ServerSocket to listen for connections.
|
||||
* Start the thread.
|
||||
*/
|
||||
public AbstractServer(int port, int defaultPort) {
|
||||
public AbstractServer(int port, int defaultPort) throws IOException {
|
||||
if (port == 0) {
|
||||
this.port = defaultPort;
|
||||
} else {
|
||||
this.port = port;
|
||||
}
|
||||
try {
|
||||
//noinspection SocketOpenedButNotSafelyClosed
|
||||
serverSocket = new ServerSocket(port);
|
||||
} catch (IOException e) {
|
||||
DavGatewayTray.error("Exception creating server socket", e);
|
||||
}
|
||||
//noinspection SocketOpenedButNotSafelyClosed
|
||||
serverSocket = new ServerSocket(port);
|
||||
}
|
||||
|
||||
|
||||
@ -74,7 +70,9 @@ public abstract class AbstractServer extends Thread {
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
serverSocket.close();
|
||||
if (serverSocket != null) {
|
||||
serverSocket.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
DavGatewayTray.warn("Exception closing server socket", e);
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package davmail;
|
||||
import davmail.pop.PopServer;
|
||||
import davmail.smtp.SmtpServer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* DavGateway main class
|
||||
*/
|
||||
@ -56,13 +58,18 @@ public class DavGateway {
|
||||
if (popPort == 0) {
|
||||
popPort = PopServer.DEFAULT_PORT;
|
||||
}
|
||||
smtpServer = new SmtpServer(smtpPort);
|
||||
popServer = new PopServer(popPort);
|
||||
smtpServer.start();
|
||||
popServer.start();
|
||||
|
||||
DavGatewayTray.info("DavMail gateway listening on SMTP port " + smtpPort +
|
||||
" and POP port " + popPort);
|
||||
try {
|
||||
smtpServer = new SmtpServer(smtpPort);
|
||||
popServer = new PopServer(popPort);
|
||||
smtpServer.start();
|
||||
popServer.start();
|
||||
|
||||
DavGatewayTray.info("DavMail gateway listening on SMTP port " + smtpPort +
|
||||
" and POP port " + popPort);
|
||||
} catch (IOException e) {
|
||||
DavGatewayTray.error("Exception creating server socket", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package davmail.imap;
|
||||
|
||||
|
||||
import java.net.Socket;
|
||||
import java.io.IOException;
|
||||
|
||||
import davmail.AbstractServer;
|
||||
import davmail.AbstractConnection;
|
||||
@ -16,7 +17,7 @@ public class ImapServer extends AbstractServer {
|
||||
* Create a ServerSocket to listen for connections.
|
||||
* Start the thread.
|
||||
*/
|
||||
public ImapServer(int port) {
|
||||
public ImapServer(int port) throws IOException {
|
||||
super(port, ImapServer.DEFAULT_PORT);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import davmail.AbstractServer;
|
||||
import davmail.AbstractConnection;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Pop3 server
|
||||
@ -17,7 +18,7 @@ public class PopServer extends AbstractServer {
|
||||
* Start the thread.
|
||||
* @param port pop listen port, 110 if not defined (0)
|
||||
*/
|
||||
public PopServer(int port) {
|
||||
public PopServer(int port) throws IOException {
|
||||
super(port, PopServer.DEFAULT_PORT);
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import davmail.AbstractServer;
|
||||
import davmail.AbstractConnection;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SmtpServer extends AbstractServer {
|
||||
public static final int DEFAULT_PORT = 25;
|
||||
@ -12,7 +13,7 @@ public class SmtpServer extends AbstractServer {
|
||||
* Create a ServerSocket to listen for connections.
|
||||
* Start the thread.
|
||||
*/
|
||||
public SmtpServer(int port) {
|
||||
public SmtpServer(int port) throws IOException {
|
||||
super(port, SmtpServer.DEFAULT_PORT);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user