bigdaddydad / android-xbmcremote

Automatically exported from code.google.com/p/android-xbmcremote
0 stars 0 forks source link

Patch for /trunk/XBMC Remote/src/org/xbmc/eventclient/Packet.java #504

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hallo,

a couple of months ago I implemented an event client (running with Java on 
Linux, not Android) which listens to a Fritzbox (router with ISDN) for my 
phone-line status.

The functionality was more or less a joke for my wife, if a call comes in it 
sends a pause to XBMC....

Anyway, this event client was running for multiple hours untill I got a file 
handle problem... after looking through your code I found that you don't close 
the "DatagramSocket".

This patch should fix problems with longer running Event Clients.

Best wishes,
Robin

Original issue reported on code.google.com by robin.k...@gmail.com on 15 Apr 2011 at 2:52

Attachments:

GoogleCodeExporter commented 8 years ago
P.S.
For those who think the close isn't needed: this close makes a native call, 
without having a finalized (which is a bad idea in general) this native call 
will not be made therefor the resources aren't freed.

Actually there should be a try / finally around the code to make it also work 
in case of problems:
/**
 * Sends this packet to the EventServer
 * @param adr Address of the EventServer
 * @param port Port of the EventServer
 * @throws IOException
 */
public void send(InetAddress adr, int port) throws IOException
{
    int maxseq = getNumPackets();
    DatagramSocket s = new DatagramSocket();
    try {
        // For each Packet in Sequence...
        for(int seq=1;seq<=maxseq;seq++)
        {
            // Get Message and send them...
            byte[] pack = getUDPMessage(seq);
            DatagramPacket p = new DatagramPacket(pack, pack.length);
            p.setAddress(adr);
            p.setPort(port);
            s.send(p);
        }
    } finally {
        s.close();
    }
}

Original comment by robin.k...@gmail.com on 15 Apr 2011 at 2:59

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r771.

Original comment by till.ess...@googlemail.com on 24 May 2011 at 8:29