769 continue; |
769 continue; |
770 } |
770 } |
771 } // end of while |
771 } // end of while |
772 } |
772 } |
773 } |
773 } |
|
774 DatagramPacket tmp = null; |
774 if ((connectState == ST_CONNECTED_NO_IMPL) || explicitFilter) { |
775 if ((connectState == ST_CONNECTED_NO_IMPL) || explicitFilter) { |
775 // We have to do the filtering the old fashioned way since |
776 // We have to do the filtering the old fashioned way since |
776 // the native impl doesn't support connect or the connect |
777 // the native impl doesn't support connect or the connect |
777 // via the impl failed, or .. "explicitFilter" may be set when |
778 // via the impl failed, or .. "explicitFilter" may be set when |
778 // a socket is connected via the impl, for a period of time |
779 // a socket is connected via the impl, for a period of time |
793 peekPort = getImpl().peek(peekAddress); |
794 peekPort = getImpl().peek(peekAddress); |
794 } |
795 } |
795 if ((!connectedAddress.equals(peekAddress)) || |
796 if ((!connectedAddress.equals(peekAddress)) || |
796 (connectedPort != peekPort)) { |
797 (connectedPort != peekPort)) { |
797 // throw the packet away and silently continue |
798 // throw the packet away and silently continue |
798 DatagramPacket tmp = new DatagramPacket( |
799 tmp = new DatagramPacket( |
799 new byte[1024], 1024); |
800 new byte[1024], 1024); |
800 getImpl().receive(tmp); |
801 getImpl().receive(tmp); |
801 if (explicitFilter) { |
802 if (explicitFilter) { |
802 bytesLeftToFilter -= tmp.getLength(); |
803 if (checkFiltering(tmp)) { |
|
804 stop = true; |
|
805 } |
803 } |
806 } |
804 } else { |
807 } else { |
805 stop = true; |
808 stop = true; |
806 } |
809 } |
807 } |
810 } |
808 } |
811 } |
809 // If the security check succeeds, or the datagram is |
812 // If the security check succeeds, or the datagram is |
810 // connected then receive the packet |
813 // connected then receive the packet |
811 getImpl().receive(p); |
814 getImpl().receive(p); |
812 if (explicitFilter) { |
815 if (explicitFilter && tmp == null) { |
813 bytesLeftToFilter -= p.getLength(); |
816 // packet was not filtered, account for it here |
814 if (bytesLeftToFilter <= 0) { |
817 checkFiltering(p); |
815 explicitFilter = false; |
|
816 } else { |
|
817 // break out of filter, if there is no more data queued |
|
818 explicitFilter = getImpl().dataAvailable() > 0; |
|
819 } |
|
820 } |
818 } |
821 } |
819 } |
|
820 } |
|
821 |
|
822 private boolean checkFiltering(DatagramPacket p) throws SocketException { |
|
823 bytesLeftToFilter -= p.getLength(); |
|
824 if (bytesLeftToFilter <= 0 || getImpl().dataAvailable() <= 0) { |
|
825 explicitFilter = false; |
|
826 return true; |
|
827 } |
|
828 return false; |
822 } |
829 } |
823 |
830 |
824 /** |
831 /** |
825 * Gets the local address to which the socket is bound. |
832 * Gets the local address to which the socket is bound. |
826 * |
833 * |