Skip to content

Commit 5a34cda

Browse files
Merge pull request #5 from benceszigeti/main
Rework Datagram Socket parameters
2 parents 3bc5deb + fe9a509 commit 5a34cda

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ After installing the package, you can use the provided [opensips-mi](opensips/mi
7878
- `-fb` or `--fifo-fallback` - the path to the FIFO fallback file.
7979
- `-fd` or `--fifo-reply-dir` - the directory where the FIFO reply files are stored.
8080
- `--env-file` - the path to the environment file that contains the MI parameters (by default, the script will look for the `.env` file in the current directory); lower priority than the command line arguments.
81+
- `-ds` or `--datagram-socket` - Unix Datagram Socket.
82+
- `-dt` or `--datagram-timeout` - Datagram Socket timeout in seconds. Default is 0.1.
83+
- `-db` or `--datagram-buffer-size` - Datagram Socket buffer size in bytes. Default is 32768.
8184

8285
#### Usage
8386
```bash

opensips/mi/__main__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ def load_env_file(env_file_path):
7070
communication.add_argument('-ds', '--datagram-socket',
7171
metavar='SOCK',
7272
type=str,
73-
help='OpenSIPS Datagram Socket')
73+
help='OpenSIPS Unix Datagram Socket')
74+
communication.add_argument('-dt', '--datagram-timeout',
75+
type=int,
76+
help='OpenSIPS Datagram Socket Timeout')
77+
communication.add_argument('-db', '--datagram-buffer-size',
78+
type=int,
79+
help='OpenSIPS Datagram Socket Buffer Size')
7480

7581
group = parser.add_mutually_exclusive_group(required=True)
7682

@@ -135,12 +141,14 @@ def main():
135141
if args.datagram_socket:
136142
mi = OpenSIPSMI('datagram',
137143
datagram_unix_socket=args.datagram_socket,
138-
timeout=0.1)
144+
datagram_timeout=args.datagram_timeout,
145+
datagram_buffer_size=args.datagram_buffer_size)
139146
else:
140147
mi = OpenSIPSMI('datagram',
141148
datagram_ip=args.ip,
142149
datagram_port=args.port,
143-
timeout=0.1)
150+
datagram_timeout=args.datagram_timeout,
151+
datagram_buffer_size=args.datagram_buffer_size)
144152
else:
145153
if not args.bash_complete:
146154
print(f'Unknown type: {args.type}')

opensips/mi/datagram.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,17 @@ def __init__(self, **kwargs):
3232
if "datagram_unix_socket" in kwargs:
3333
self.address = kwargs["datagram_unix_socket"]
3434
self.family = socket.AF_UNIX
35-
self.recv_size = 65535 * 32
3635
with NamedTemporaryFile(prefix="opensips_mi_reply_", dir="/tmp") as nt:
3736
self.recv_sock = nt.name
3837
elif "datagram_ip" in kwargs and "datagram_port" in kwargs:
3938
self.address = (kwargs["datagram_ip"], int(kwargs["datagram_port"]))
4039
self.family = socket.AF_INET
41-
self.recv_size = 32768
4240
self.recv_sock = None
4341
else:
4442
raise ValueError("Either datagram_unix_socket or both datagram_ip and datagram_port are required for Datagram")
4543

46-
self.timeout = kwargs.get("timeout", 1)
44+
self.timeout = float(kwargs.get("datagram_timeout") or 0.1)
45+
self.recv_size = int(kwargs.get("datagram_buffer_size") or 32768)
4746

4847
def execute(self, method: str, params: dict):
4948
jsoncmd = jsonrpc_helper.get_command(method, params)

opensips/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

2020
""" OpenSIPS Package version """
2121

22-
__version__ = '0.1.6'
22+
__version__ = '0.1.7'

0 commit comments

Comments
 (0)