< Summary - Jellyfin

Information
Class: Jellyfin.Networking.Udp.SocketFactory
Assembly: Jellyfin.Networking
File(s): /srv/git/jellyfin/src/Jellyfin.Networking/Udp/SocketFactory.cs
Line coverage
66%
Covered lines: 8
Uncovered lines: 4
Coverable lines: 12
Total lines: 38
Line coverage: 66.6%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CreateUdpBroadcastSocket(...)50%2.15266.66%

File(s)

/srv/git/jellyfin/src/Jellyfin.Networking/Udp/SocketFactory.cs

#LineLine coverage
 1using System;
 2using System.Net;
 3using System.Net.Sockets;
 4using MediaBrowser.Model.Net;
 5
 6namespace Jellyfin.Networking.Udp;
 7
 8/// <summary>
 9/// Factory class to create different kinds of sockets.
 10/// </summary>
 11public class SocketFactory : ISocketFactory
 12{
 13    /// <inheritdoc />
 14    public Socket CreateUdpBroadcastSocket(int localPort)
 15    {
 116        if (localPort < 0)
 17        {
 018            throw new ArgumentException("localPort cannot be less than zero.", nameof(localPort));
 19        }
 20
 121        var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
 22        try
 23        {
 124            socket.EnableBroadcast = true;
 125            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
 126            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
 127            socket.Bind(new IPEndPoint(IPAddress.Any, localPort));
 28
 129            return socket;
 30        }
 031        catch
 32        {
 033            socket.Dispose();
 34
 035            throw;
 36        }
 137    }
 38}