package com.google.android.gms.internal.ads; import android.net.Uri; import androidx.annotation.Nullable; import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.MulticastSocket; import java.net.SocketTimeoutException; /* loaded from: classes3.dex */ public final class zzha extends zzfr { private final byte[] zza; private final DatagramPacket zzb; @Nullable private Uri zzc; @Nullable private DatagramSocket zzd; @Nullable private MulticastSocket zze; @Nullable private InetAddress zzf; private boolean zzg; private int zzh; public zzha() { throw null; } public zzha(int i) { super(true); byte[] bArr = new byte[2000]; this.zza = bArr; this.zzb = new DatagramPacket(bArr, 0, 2000); } @Override // com.google.android.gms.internal.ads.zzfy public final long zzb(zzgd zzgdVar) throws zzgz { Uri uri = zzgdVar.zza; this.zzc = uri; String host = uri.getHost(); host.getClass(); int port = this.zzc.getPort(); zzi(zzgdVar); try { this.zzf = InetAddress.getByName(host); InetSocketAddress inetSocketAddress = new InetSocketAddress(this.zzf, port); if (this.zzf.isMulticastAddress()) { MulticastSocket multicastSocket = new MulticastSocket(inetSocketAddress); this.zze = multicastSocket; multicastSocket.joinGroup(this.zzf); this.zzd = this.zze; } else { this.zzd = new DatagramSocket(inetSocketAddress); } this.zzd.setSoTimeout(8000); this.zzg = true; zzj(zzgdVar); return -1L; } catch (IOException e) { throw new zzgz(e, 2001); } catch (SecurityException e2) { throw new zzgz(e2, 2006); } } @Override // com.google.android.gms.internal.ads.zzfy @Nullable public final Uri zzc() { return this.zzc; } @Override // com.google.android.gms.internal.ads.zzfy public final void zzd() { this.zzc = null; MulticastSocket multicastSocket = this.zze; if (multicastSocket != null) { try { InetAddress inetAddress = this.zzf; inetAddress.getClass(); multicastSocket.leaveGroup(inetAddress); } catch (IOException unused) { } this.zze = null; } DatagramSocket datagramSocket = this.zzd; if (datagramSocket != null) { datagramSocket.close(); this.zzd = null; } this.zzf = null; this.zzh = 0; if (this.zzg) { this.zzg = false; zzh(); } } @Override // com.google.android.gms.internal.ads.zzl public final int zza(byte[] bArr, int i, int i2) throws zzgz { if (i2 == 0) { return 0; } if (this.zzh == 0) { try { DatagramSocket datagramSocket = this.zzd; datagramSocket.getClass(); datagramSocket.receive(this.zzb); int length = this.zzb.getLength(); this.zzh = length; zzg(length); } catch (SocketTimeoutException e) { throw new zzgz(e, 2002); } catch (IOException e2) { throw new zzgz(e2, 2001); } } int length2 = this.zzb.getLength(); int i3 = this.zzh; int min = Math.min(i3, i2); System.arraycopy(this.zza, length2 - i3, bArr, i, min); this.zzh -= min; return min; } }