• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

azjezz / psl / 9286105259

29 May 2024 12:29PM UTC coverage: 87.311% (-10.0%) from 97.267%
9286105259

Pull #451

github

azjezz
feat(tcp): support TLS/SSL

Signed-off-by: azjezz <azjezz@protonmail.com>
Pull Request #451: feat(tcp): add support for TLS/SSL in TCP

37 of 627 new or added lines in 16 files covered. (5.9%)

2 existing lines in 1 file now uncovered.

5030 of 5761 relevant lines covered (87.31%)

46.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/src/Psl/Network/SocketOptions.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\Network;
6

7
use Psl\Default\DefaultInterface;
8

9
/**
10
 * Encapsulates socket options for network operations.
11
 *
12
 * @psalm-immutable
13
 */
14
final readonly class SocketOptions implements DefaultInterface
15
{
16
    /**
17
     * Initializes a new instance of SocketOptions with the specified settings.
18
     *
19
     * @param bool $addressReuse Enables or disables the SO_REUSEADDR socket option.
20
     * @param bool $portReuse Enables or disables the SO_REUSEPORT socket option.
21
     * @param bool $broadcast Enables or disables the SO_BROADCAST socket option.
22
     *
23
     * @psalm-mutation-free
24
     */
25
    public function __construct(
26
        public readonly bool $addressReuse,
27
        public readonly bool $portReuse,
28
        public readonly bool $broadcast,
29
        public readonly int $backlog,
30
    ) {
31
    }
11✔
32

33
    /**
34
     * Constructs a new SocketOptions instance with the specified settings.
35
     *
36
     * This static factory method facilitates the creation of SocketOptions instances,
37
     * allowing for explicit and readable configuration of socket behavior at instantiation.
38
     *
39
     * @param bool $address_reuse Determines the SO_REUSEADDR socket option state.
40
     * @param bool $port_reuse Determines the SO_REUSEPORT socket option state.
41
     * @param bool $broadcast Determines the SO_BROADCAST socket option state.
42
     * @param positive-int $backlog A maximum of backlog incoming connections will be queued for processing.
43
     *
44
     * @pure
45
     */
46
    public static function create(bool $address_reuse = false, bool $port_reuse = false, bool $broadcast = false, int $backlog = 128): SocketOptions
47
    {
48
        return new self($address_reuse, $port_reuse, $broadcast, $backlog);
11✔
49
    }
50

51
    /**
52
     * Provides a default set of socket options.
53
     *
54
     * The default instance has all options disabled, creating a conservative and
55
     * safe starting point for socket configuration.
56
     *
57
     * @pure
58
     */
59
    public static function default(): static
60
    {
61
        return self::create();
10✔
62
    }
63

64
    /**
65
     * Returns a new instance with the address reuse option modified.
66
     *
67
     * @param bool $enabled The desired state for the SO_REUSEADDR option.
68
     *
69
     * @psalm-mutation-free
70
     */
71
    public function withAddressReuse(bool $enabled = true): SocketOptions
72
    {
73
        return new self($enabled, $this->portReuse, $this->broadcast, $this->backlog);
2✔
74
    }
75

76
    /**
77
     * Returns a new instance with the port reuse option modified.
78
     *
79
     * @param bool $enabled The desired state for the SO_REUSEPORT option.
80
     *
81
     * @psalm-mutation-free
82
     */
83
    public function withPortReuse(bool $enabled = true): SocketOptions
84
    {
85
        return new self($this->addressReuse, $enabled, $this->broadcast, $this->backlog);
2✔
86
    }
87

88
    /**
89
     * Returns a new instance with the broadcast option modified.
90
     *
91
     * @param bool $enabled The desired state for the SO_BROADCAST option.
92
     *
93
     * @psalm-mutation-free
94
     */
95
    public function withBroadcast(bool $enabled = true): SocketOptions
96
    {
97
        return new self($this->addressReuse, $this->portReuse, $enabled, $this->backlog);
3✔
98
    }
99

100
    /**
101
     * Returns a new instance with the backlog option modified.
102
     *
103
     * @param positive-int $backlog A maximum of backlog incoming connections will be queued for processing.
104
     *
105
     * @mutation-free
106
     */
107
    public function withBacklog(int $backlog): SocketOptions
108
    {
NEW
109
        return new self($this->addressReuse, $this->portReuse, $this->broadcast, $backlog);
×
110
    }
111
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc