Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libnice
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mathieu Duponchelle
libnice
Commits
4f456a46
Commit
4f456a46
authored
Jan 30, 2014
by
Olivier Crête
👻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove the "length" parameter from NiceOutputMessage
It was used correctly only half the time anyway
parent
5c235a86
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
142 additions
and
102 deletions
+142
-102
agent/agent-priv.h
agent/agent-priv.h
+5
-1
agent/agent.c
agent/agent.c
+56
-35
agent/agent.h
agent/agent.h
+0
-2
agent/outputstream.c
agent/outputstream.c
+2
-2
socket/http.c
socket/http.c
+5
-6
socket/pseudossl.c
socket/pseudossl.c
+9
-5
socket/socket.c
socket/socket.c
+1
-2
socket/socks5.c
socket/socks5.c
+5
-4
socket/tcp-bsd.c
socket/tcp-bsd.c
+22
-17
socket/tcp-turn.c
socket/tcp-turn.c
+4
-6
socket/turn.c
socket/turn.c
+11
-15
tests/test-bsd.c
tests/test-bsd.c
+0
-1
tests/test-send-recv.c
tests/test-send-recv.c
+22
-6
No files found.
agent/agent-priv.h
View file @
4f456a46
...
...
@@ -215,9 +215,13 @@ gsize
memcpy_buffer_to_input_message
(
NiceInputMessage
*
message
,
const
guint8
*
buffer
,
gsize
buffer_length
);
guint8
*
compact_input_message
(
NiceInputMessage
*
message
,
gsize
*
buffer_length
);
compact_input_message
(
const
NiceInputMessage
*
message
,
gsize
*
buffer_length
);
guint8
*
compact_output_message
(
const
NiceOutputMessage
*
message
,
gsize
*
buffer_length
);
gsize
output_message_get_size
(
const
NiceOutputMessage
*
message
);
#endif
/*_NICE_AGENT_PRIV_H */
agent/agent.c
View file @
4f456a46
...
...
@@ -84,7 +84,8 @@
#define MAX_TCP_MTU 1400
/* Use 1400 because of VPNs and we assume IEE 802.3 */
static
void
nice_debug_message_composition
(
NiceInputMessage
*
messages
,
guint
n_messages
);
nice_debug_input_message_composition
(
const
NiceInputMessage
*
messages
,
guint
n_messages
);
G_DEFINE_TYPE
(
NiceAgent
,
nice_agent
,
G_TYPE_OBJECT
);
...
...
@@ -1050,7 +1051,8 @@ pseudo_tcp_socket_send_messages (PseudoTcpSocket *self,
* used in reliable mode, and there is no concept of a ‘message’, but is
* necessary because the calling API has no way of returning to the client
* and indicating that a message was partially sent. */
if
(
message
->
length
>
pseudo_tcp_socket_get_available_send_space
(
self
))
{
if
(
output_message_get_size
(
message
)
>
pseudo_tcp_socket_get_available_send_space
(
self
))
{
return
i
;
}
...
...
@@ -1232,7 +1234,7 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data)
nice_debug
(
"%s: Client buffers case: Received %d valid messages:"
,
G_STRFUNC
,
n_valid_messages
);
nice_debug_message_composition
(
component
->
recv_messages
,
nice_debug_
input_
message_composition
(
component
->
recv_messages
,
component
->
n_recv_messages
);
if
(
n_valid_messages
<
0
)
{
...
...
@@ -1292,8 +1294,6 @@ pseudo_tcp_socket_write_packet (PseudoTcpSocket *socket,
if
(
component
->
selected_pair
.
local
!=
NULL
)
{
NiceSocket
*
sock
;
NiceAddress
*
addr
;
GOutputVector
local_buf
;
NiceOutputMessage
local_message
;
sock
=
component
->
selected_pair
.
local
->
sockptr
;
...
...
@@ -1312,15 +1312,8 @@ pseudo_tcp_socket_write_packet (PseudoTcpSocket *socket,
addr
=
&
component
->
selected_pair
.
remote
->
addr
;
local_buf
.
buffer
=
buffer
;
local_buf
.
size
=
len
;
local_message
.
buffers
=
&
local_buf
;
local_message
.
n_buffers
=
1
;
local_message
.
length
=
len
;
if
(
nice_socket_send_messages
(
sock
,
addr
,
&
local_message
,
1
))
{
if
(
nice_socket_send
(
sock
,
addr
,
len
,
buffer
))
return
WR_SUCCESS
;
}
}
else
{
nice_debug
(
"%s: WARNING: Failed to send pseudo-TCP packet from agent %p "
"as no pair has been selected yet."
,
G_STRFUNC
,
component
->
agent
);
...
...
@@ -2749,13 +2742,14 @@ done:
/* Print the composition of an array of messages. No-op if debugging is
* disabled. */
static
void
nice_debug_message_composition
(
NiceInputMessage
*
messages
,
guint
n_messages
)
nice_debug_input_message_composition
(
const
NiceInputMessage
*
messages
,
guint
n_messages
)
{
#ifndef NDEBUG
guint
i
;
for
(
i
=
0
;
i
<
n_messages
;
i
++
)
{
NiceInputMessage
*
message
=
&
messages
[
i
];
const
NiceInputMessage
*
message
=
&
messages
[
i
];
guint
j
;
nice_debug
(
"Message %p (from: %p, length: %"
G_GSIZE_FORMAT
")"
,
message
,
...
...
@@ -2774,30 +2768,20 @@ nice_debug_message_composition (NiceInputMessage *messages, guint n_messages)
#endif
}
/* Concatenate all the buffers in the given @recv_message into a single, newly
* allocated, monolithic buffer which is returned. The length of the new buffer
* is returned in @buffer_length, and should be equal to the length field of
* @recv_message.
*
* The return value must be freed with g_free(). */
guint8
*
compact_input_message
(
NiceInputMessage
*
message
,
gsize
*
buffer_length
)
static
guint8
*
compact_message
(
const
NiceOutputMessage
*
message
,
gsize
buffer_length
)
{
guint8
*
buffer
;
gsize
offset
=
0
;
guint
i
;
nice_debug
(
"%s: **WARNING: SLOW PATH**"
,
G_STRFUNC
);
nice_debug_message_composition
(
message
,
1
);
*
buffer_length
=
message
->
length
;
buffer
=
g_malloc
(
*
buffer_length
);
buffer
=
g_malloc
(
buffer_length
);
for
(
i
=
0
;
(
message
->
n_buffers
>=
0
&&
i
<
(
guint
)
message
->
n_buffers
)
||
(
message
->
n_buffers
<
0
&&
message
->
buffers
[
i
].
buffer
!=
NULL
);
i
++
)
{
gsize
len
=
MIN
(
*
buffer_length
-
offset
,
message
->
buffers
[
i
].
size
);
gsize
len
=
MIN
(
buffer_length
-
offset
,
message
->
buffers
[
i
].
size
);
memcpy
(
buffer
+
offset
,
message
->
buffers
[
i
].
buffer
,
len
);
offset
+=
len
;
}
...
...
@@ -2805,6 +2789,25 @@ compact_input_message (NiceInputMessage *message, gsize *buffer_length)
return
buffer
;
}
/* Concatenate all the buffers in the given @recv_message into a single, newly
* allocated, monolithic buffer which is returned. The length of the new buffer
* is returned in @buffer_length, and should be equal to the length field of
* @recv_message.
*
* The return value must be freed with g_free(). */
guint8
*
compact_input_message
(
const
NiceInputMessage
*
message
,
gsize
*
buffer_length
)
{
nice_debug
(
"%s: **WARNING: SLOW PATH**"
,
G_STRFUNC
);
nice_debug_input_message_composition
(
message
,
1
);
/* This works as long as NiceInputMessage is a subset of eNiceOutputMessage */
*
buffer_length
=
message
->
length
;
return
compact_message
((
NiceOutputMessage
*
)
message
,
*
buffer_length
);
}
/* Returns the number of bytes copied. Silently drops any data from @buffer
* which doesn’t fit in @message. */
gsize
...
...
@@ -2834,7 +2837,7 @@ memcpy_buffer_to_input_message (NiceInputMessage *message,
message
->
length
+=
len
;
}
nice_debug_message_composition
(
message
,
1
);
nice_debug_
input_
message_composition
(
message
,
1
);
if
(
buffer_length
>
0
)
{
g_warning
(
"Dropped %"
G_GSIZE_FORMAT
" bytes of data from the end of "
...
...
@@ -2855,9 +2858,27 @@ memcpy_buffer_to_input_message (NiceInputMessage *message,
guint8
*
compact_output_message
(
const
NiceOutputMessage
*
message
,
gsize
*
buffer_length
)
{
/* This works as long as NiceInputMessage and NiceOutputMessage are layed out
* identically. */
return
compact_input_message
((
NiceInputMessage
*
)
message
,
buffer_length
);
nice_debug
(
"%s: **WARNING: SLOW PATH**"
,
G_STRFUNC
);
*
buffer_length
=
output_message_get_size
(
message
);
return
compact_message
(
message
,
*
buffer_length
);
}
gsize
output_message_get_size
(
const
NiceOutputMessage
*
message
)
{
guint
i
;
gsize
message_len
=
0
;
/* Find the total size of the message */
for
(
i
=
0
;
(
message
->
n_buffers
>=
0
&&
i
<
(
guint
)
message
->
n_buffers
)
||
(
message
->
n_buffers
<
0
&&
message
->
buffers
[
i
].
buffer
!=
NULL
);
i
++
)
message_len
+=
message
->
buffers
[
i
].
size
;
return
message_len
;
}
/**
...
...
@@ -3034,7 +3055,7 @@ nice_agent_recv_messages_blocking_or_nonblocking (NiceAgent *agent,
}
nice_debug
(
"%s: (%s):"
,
G_STRFUNC
,
blocking
?
"blocking"
:
"non-blocking"
);
nice_debug_message_composition
(
messages
,
n_messages
);
nice_debug_
input_
message_composition
(
messages
,
n_messages
);
/* Set the component’s receive buffer. */
context
=
component_dup_io_context
(
component
);
...
...
@@ -3320,8 +3341,8 @@ nice_agent_send (
const
gchar
*
buf
)
{
GOutputVector
local_buf
=
{
buf
,
len
};
NiceOutputMessage
local_message
=
{
&
local_buf
,
1
,
len
};
gint
n_sent_messages
;
NiceOutputMessage
local_message
=
{
&
local_buf
,
1
};
n_sent_messages
=
nice_agent_send_messages_nonblocking
(
agent
,
stream_id
,
component_id
,
&
local_message
,
1
,
NULL
,
NULL
);
...
...
agent/agent.h
View file @
4f456a46
...
...
@@ -176,7 +176,6 @@ typedef struct {
* which contain data to transmit for this message
* @n_buffers: number of #GOutputVectors in @buffers, or -1 to indicate @buffers
* is %NULL-terminated
* @length: total number of valid bytes contiguously stored in @buffers
*
* Represents a single message to transmit on the network. For
* reliable connections, this is essentially just an array of
...
...
@@ -197,7 +196,6 @@ typedef struct {
typedef
struct
{
GOutputVector
*
buffers
;
gint
n_buffers
;
gsize
length
;
}
NiceOutputMessage
;
...
...
agent/outputstream.c
View file @
4f456a46
...
...
@@ -403,7 +403,7 @@ nice_output_stream_write (GOutputStream *stream, const void *buffer, gsize count
do
{
GOutputVector
local_buf
=
{
(
const
guint8
*
)
buffer
+
len
,
count
-
len
};
NiceOutputMessage
local_message
=
{
&
local_buf
,
1
,
count
-
len
};
NiceOutputMessage
local_message
=
{
&
local_buf
,
1
};
/* Have to unlock while calling into the agent because
* it will take the agent lock which will cause a deadlock if one of
...
...
@@ -523,7 +523,7 @@ nice_output_stream_write_nonblocking (GPollableOutputStream *stream,
NiceOutputStreamPrivate
*
priv
=
NICE_OUTPUT_STREAM
(
stream
)
->
priv
;
NiceAgent
*
agent
;
/* owned */
GOutputVector
local_buf
=
{
buffer
,
count
};
NiceOutputMessage
local_message
=
{
&
local_buf
,
1
,
count
};
NiceOutputMessage
local_message
=
{
&
local_buf
,
1
};
gint
n_sent_messages
;
/* Closed streams are not writeable. */
...
...
socket/http.c
View file @
4f456a46
...
...
@@ -43,6 +43,7 @@
#endif
#include "http.h"
#include "agent-priv.h"
#include <string.h>
#include <stdlib.h>
...
...
@@ -165,7 +166,6 @@ nice_http_socket_new (NiceSocket *base_socket,
local_bufs
.
size
=
strlen
(
msg
);
local_messages
.
buffers
=
&
local_bufs
;
local_messages
.
n_buffers
=
1
;
local_messages
.
length
=
local_bufs
.
size
;
nice_socket_send_messages
(
priv
->
base_socket
,
NULL
,
&
local_messages
,
1
);
priv
->
state
=
HTTP_STATE_INIT
;
...
...
@@ -266,7 +266,6 @@ memcpy_ring_buffer_to_input_messages (HttpPriv *priv,
message
->
buffers
[
j
].
size
=
memcpy_ring_buffer_to_buffer
(
priv
,
message
->
buffers
[
j
].
buffer
,
message
->
buffers
[
j
].
size
);
message
->
length
+=
message
->
buffers
[
j
].
size
;
}
}
...
...
@@ -618,15 +617,15 @@ add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
const
NiceOutputMessage
*
message
=
&
messages
[
i
];
struct
to_be_sent
*
tbs
=
NULL
;
guint
j
;
gsize
message_len_remaining
=
message
->
length
;
gsize
message_len_remaining
=
output_message_get_size
(
message
)
;
gsize
offset
=
0
;
if
(
message
->
length
==
0
)
if
(
message
_len_remaining
==
0
)
continue
;
tbs
=
g_slice_new0
(
struct
to_be_sent
);
tbs
->
buf
=
g_malloc
(
message
->
length
);
tbs
->
length
=
message
->
length
;
tbs
->
buf
=
g_malloc
(
message
_len_remaining
);
tbs
->
length
=
message
_len_remaining
;
if
(
to
)
tbs
->
to
=
*
to
;
g_queue_push_tail
(
&
priv
->
send_queue
,
tbs
);
...
...
socket/pseudossl.c
View file @
4f456a46
...
...
@@ -43,6 +43,7 @@
#endif
#include "pseudossl.h"
#include "agent-priv.h"
#include <string.h>
...
...
@@ -229,12 +230,15 @@ add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
const
NiceOutputMessage
*
message
=
&
messages
[
i
];
guint
j
;
gsize
offset
=
0
;
gsize
message_len
;
tbs
=
g_slice_new0
(
struct
to_be_sent
);
/* Compact the buffer. */
tbs
->
buf
=
g_malloc
(
message
->
length
);
tbs
->
length
=
message
->
length
;
message_len
=
output_message_get_size
(
message
);
/* Compact the buffer. */
tbs
->
buf
=
g_malloc
(
message_len
);
tbs
->
length
=
message_len
;
if
(
to
!=
NULL
)
tbs
->
to
=
*
to
;
g_queue_push_tail
(
&
priv
->
send_queue
,
tbs
);
...
...
@@ -246,12 +250,12 @@ add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
const
GOutputVector
*
buffer
=
&
message
->
buffers
[
j
];
gsize
len
;
len
=
MIN
(
message
->
length
-
offset
,
buffer
->
size
);
len
=
MIN
(
message
_len
-
offset
,
buffer
->
size
);
memcpy
(
tbs
->
buf
+
offset
,
buffer
->
buffer
,
len
);
offset
+=
len
;
}
g_assert
_cmpuint
(
offset
,
==
,
message
->
length
);
g_assert
(
offset
==
message_len
);
}
}
...
...
socket/socket.c
View file @
4f456a46
...
...
@@ -146,7 +146,7 @@ nice_socket_send (NiceSocket *sock, const NiceAddress *to, gsize len,
const
gchar
*
buf
)
{
GOutputVector
local_buf
=
{
buf
,
len
};
NiceOutputMessage
local_message
=
{
&
local_buf
,
1
,
len
};
NiceOutputMessage
local_message
=
{
&
local_buf
,
1
};
gint
ret
;
ret
=
sock
->
send_messages
(
sock
,
to
,
&
local_message
,
1
);
...
...
@@ -169,4 +169,3 @@ nice_socket_free (NiceSocket *sock)
g_slice_free
(
NiceSocket
,
sock
);
}
}
socket/socks5.c
View file @
4f456a46
...
...
@@ -43,6 +43,7 @@
#endif
#include "socks5.h"
#include "agent-priv.h"
#include <string.h>
...
...
@@ -463,8 +464,8 @@ add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
tbs
=
g_slice_new0
(
struct
to_be_sent
);
/* Compact the buffer. */
tbs
->
buf
=
g_malloc
(
message
->
length
);
tbs
->
length
=
message
->
length
;
tbs
->
length
=
output_message_get_size
(
message
);
tbs
->
buf
=
g_malloc
(
tbs
->
length
)
;
if
(
to
!=
NULL
)
tbs
->
to
=
*
to
;
g_queue_push_tail
(
&
priv
->
send_queue
,
tbs
);
...
...
@@ -476,12 +477,12 @@ add_to_be_sent (NiceSocket *sock, const NiceAddress *to,
const
GOutputVector
*
buffer
=
&
message
->
buffers
[
j
];
gsize
len
;
len
=
MIN
(
message
->
length
-
offset
,
buffer
->
size
);
len
=
MIN
(
tbs
->
length
-
offset
,
buffer
->
size
);
memcpy
(
tbs
->
buf
+
offset
,
buffer
->
buffer
,
len
);
offset
+=
len
;
}
g_assert
_cmpuint
(
offset
,
==
,
message
->
length
);
g_assert
(
offset
==
tbs
->
length
);
}
}
...
...
socket/tcp-bsd.c
View file @
4f456a46
...
...
@@ -78,7 +78,7 @@ static gboolean socket_is_reliable (NiceSocket *sock);
static
void
add_to_be_sent
(
NiceSocket
*
sock
,
const
NiceOutputMessage
*
message
,
gsize
message_offset
,
gboolean
head
);
gsize
message_offset
,
g
size
message_len
,
g
boolean
head
);
static
void
free_to_be_sent
(
struct
to_be_sent
*
tbs
);
static
gboolean
socket_send_more
(
GSocket
*
gsocket
,
GIOCondition
condition
,
gpointer
data
);
...
...
@@ -258,12 +258,15 @@ socket_send_message (NiceSocket *sock, const NiceOutputMessage *message)
TcpPriv
*
priv
=
sock
->
priv
;
gssize
ret
;
GError
*
gerr
=
NULL
;
gsize
message_len
;
/* Don't try to access the socket if it had an error, otherwise we risk a
* crash with SIGPIPE (Broken pipe) */
if
(
priv
->
error
)
return
-
1
;
message_len
=
output_message_get_size
(
message
);
/* First try to send the data, don't send it later if it can be sent now
* this way we avoid allocating memory on every send */
if
(
g_queue_is_empty
(
&
priv
->
send_queue
))
{
...
...
@@ -274,15 +277,15 @@ socket_send_message (NiceSocket *sock, const NiceOutputMessage *message)
if
(
g_error_matches
(
gerr
,
G_IO_ERROR
,
G_IO_ERROR_WOULD_BLOCK
)
||
g_error_matches
(
gerr
,
G_IO_ERROR
,
G_IO_ERROR_FAILED
))
{
/* Queue the message and send it later. */
add_to_be_sent
(
sock
,
message
,
0
,
FALSE
);
ret
=
message
->
length
;
add_to_be_sent
(
sock
,
message
,
0
,
message_len
,
FALSE
);
ret
=
message
_len
;
}
g_error_free
(
gerr
);
}
else
if
((
gsize
)
ret
<
message
->
length
)
{
}
else
if
((
gsize
)
ret
<
message
_len
)
{
/* Partial send. */
add_to_be_sent
(
sock
,
message
,
ret
,
TRUE
);
ret
=
message
->
length
;
add_to_be_sent
(
sock
,
message
,
ret
,
message_len
,
TRUE
);
ret
=
message
_len
;
}
}
else
{
/* FIXME: This dropping will break http/socks5/etc
...
...
@@ -305,8 +308,8 @@ socket_send_message (NiceSocket *sock, const NiceOutputMessage *message)
}
/* Queue the message and send it later. */
add_to_be_sent
(
sock
,
message
,
0
,
FALSE
);
ret
=
message
->
length
;
add_to_be_sent
(
sock
,
message
,
0
,
message_len
,
FALSE
);
ret
=
message
_len
;
}
return
ret
;
...
...
@@ -389,9 +392,9 @@ socket_send_more (
if
(
gerr
!=
NULL
&&
g_error_matches
(
gerr
,
G_IO_ERROR
,
G_IO_ERROR_WOULD_BLOCK
))
{
GOutputVector
local_buf
=
{
tbs
->
buf
,
tbs
->
length
};
NiceOutputMessage
local_message
=
{
&
local_buf
,
1
,
local_buf
.
size
};
NiceOutputMessage
local_message
=
{
&
local_buf
,
1
};
add_to_be_sent
(
sock
,
&
local_message
,
0
,
TRUE
);
add_to_be_sent
(
sock
,
&
local_message
,
0
,
local_buf
.
size
,
TRUE
);
free_to_be_sent
(
tbs
);
g_error_free
(
gerr
);
break
;
...
...
@@ -399,9 +402,9 @@ socket_send_more (
g_error_free
(
gerr
);
}
else
if
(
ret
<
(
int
)
tbs
->
length
)
{
GOutputVector
local_buf
=
{
tbs
->
buf
+
ret
,
tbs
->
length
-
ret
};
NiceOutputMessage
local_message
=
{
&
local_buf
,
1
,
local_buf
.
size
};
NiceOutputMessage
local_message
=
{
&
local_buf
,
1
};
add_to_be_sent
(
sock
,
&
local_message
,
0
,
TRUE
);
add_to_be_sent
(
sock
,
&
local_message
,
0
,
local_buf
.
size
,
TRUE
);
free_to_be_sent
(
tbs
);
break
;
}
...
...
@@ -424,22 +427,24 @@ socket_send_more (
/* Queue data starting at byte offset @message_offset from @message’s
* buffers. */
* buffers.
*
* Returns the message's length */
static
void
add_to_be_sent
(
NiceSocket
*
sock
,
const
NiceOutputMessage
*
message
,
gsize
message_offset
,
gboolean
head
)
gsize
message_offset
,
g
size
message_len
,
g
boolean
head
)
{
TcpPriv
*
priv
=
sock
->
priv
;
struct
to_be_sent
*
tbs
;
guint
j
;
gsize
offset
=
0
;
if
(
message_offset
>=
message
->
length
)
if
(
message_offset
>=
message
_len
)
return
;
tbs
=
g_slice_new0
(
struct
to_be_sent
);
tbs
->
buf
=
g_malloc
(
message
->
length
-
message_offset
)
;
tbs
->
length
=
message
->
length
-
message_offset
;
tbs
->
length
=
message_len
-
message_offset
;
tbs
->
buf
=
g_malloc
(
tbs
->
length
)
;
tbs
->
can_drop
=
!
head
;
if
(
head
)
...
...
socket/tcp-turn.c
View file @
4f456a46
...
...
@@ -250,7 +250,6 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
local_bufs
=
g_malloc_n
(
n_bufs
+
2
,
sizeof
(
GOutputVector
));
local_message
.
buffers
=
local_bufs
;
local_message
.
n_buffers
=
n_bufs
+
2
;
local_message
.
length
=
message
->
length
;
/* Copy the existing buffers across. */
for
(
j
=
0
;
j
<
n_bufs
;
j
++
)
{
...
...
@@ -260,11 +259,10 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
/* Header buffer. */
if
(
priv
->
compatibility
==
NICE_TURN_SOCKET_COMPATIBILITY_GOOGLE
)
{
header_buf
=
htons
(
message
->
length
);
header_buf
=
htons
(
output_message_get_size
(
message
)
);
local_bufs
[
0
].
buffer
=
&
header_buf
;
local_bufs
[
0
].
size
=
sizeof
(
header_buf
);
local_message
.
length
+=
sizeof
(
header_buf
);
}
else
{
/* Skip over the allocated header buffer. */
local_message
.
buffers
++
;
...
...
@@ -274,11 +272,11 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
/* Tail buffer. */
if
(
priv
->
compatibility
==
NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9
||
priv
->
compatibility
==
NICE_TURN_SOCKET_COMPATIBILITY_RFC5766
)
{
gsize
padlen
=
(
message
->
length
%
4
)
?
4
-
(
message
->
length
%
4
)
:
0
;
gsize
message_len
=
output_message_get_size
(
message
);
gsize
padlen
=
(
message_len
%
4
)
?
4
-
(
message_len
%
4
)
:
0
;
local_bufs
[
n_bufs
].
buffer
=
&
padbuf
;
local_bufs
[
n_bufs
].
size
=
padlen
;
local_message
.
length
+=
padlen
;
}
else
{
/* Skip over the allocated tail buffer. */
local_message
.
n_buffers
--
;
...
...
@@ -289,7 +287,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
g_free
(
local_bufs
);
if
(
ret
==
1
)
return
local_message
.
length
;
return
output_message_get_size
(
&
local_message
)
;
return
ret
;
}
...
...
socket/turn.c
View file @
4f456a46
...
...
@@ -576,16 +576,18 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
if
(
binding
)
{
if
(
priv
->
compatibility
==
NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9
||
priv
->
compatibility
==
NICE_TURN_SOCKET_COMPATIBILITY_RFC5766
)
{
if
(
message
->
length
+
sizeof
(
uint32_t
)
<=
sizeof
(
buffer
))
{
gsize
message_len
=
output_message_get_size
(
message
);
if
(
message_len
+
sizeof
(
uint32_t
)
<=
sizeof
(
buffer
))
{
guint
j
;
uint16_t
len16
,
channel16
;
gsize
message_offset
=
0
;
len16
=
htons
((
uint16_t
)
message
->
length
);
len16
=
htons
((
uint16_t
)
message
_len
);
channel16
=
htons
(
binding
->
channel
);
memcpy
(
buffer
,
&
channel16
,
sizeof
(
uint16_t
));
memcpy
(
buffer
+
sizeof
(
uint16_t
),
&
len16
,
sizeof
(
uint16_t
));
memcpy
(
buffer
+
sizeof
(
uint16_t
),
&
len16
,
sizeof
(
uint16_t
));
/* FIXME: Slow path! This should be replaced by code which manipulates
* the GOutputVector array, rather than the buffer contents
...
...
@@ -597,25 +599,21 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
const
GOutputVector
*
out_buf
=
&
message
->
buffers
[
j
];
gsize
out_len
;
out_len
=
MIN
(
message
->
length
-
message_offset
,
out_buf
->
size
);
out_len
=
MIN
(
message
_len
-
message_offset
,
out_buf
->
size
);
memcpy
(
buffer
+
sizeof
(
uint32_t
)
+
message_offset
,
out_buf
->
buffer
,
out_len
);
message_offset
+=
out_len
;
}
msg_len
=
message
->
length
+
sizeof
(
uint32_t
);
msg_len
=
message
_len
+
sizeof
(
uint32_t
);
}
else
{
return
0
;
}
}
else
{
NiceOutputMessage
local_message
=
{
message
->
buffers
,
message
->
n_buffers
,
message
->
length
};
ret
=
nice_socket_send_messages
(
priv
->
base_socket
,
&
priv
->
server_addr
,
&
local_
message
,
1
);
message
,
1
);
if
(
ret
==
1
)
return
message
->
length
;
return
output_message_get_size
(
message
)
;
return
ret
;
}
}
else
{
...
...
@@ -708,7 +706,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
return
msg_len
;
}
else
{
GOutputVector
local_buf
=
{
buffer
,
msg_len
};
NiceOutputMessage
local_message
=
{
&
local_buf
,
1
,
msg_len
};
NiceOutputMessage
local_message
=
{
&
local_buf
,
1
};
ret
=
nice_socket_send_messages
(
priv
->
base_socket
,
&
priv
->
server_addr
,
&
local_message
,
1
);
...
...
@@ -722,7 +720,7 @@ send:
/* Error condition pass through to the base socket. */
ret
=
nice_socket_send_messages
(
priv
->
base_socket
,
to
,
message
,
1
);
if
(
ret
==
1
)
return
message
->
length
;
return
output_message_get_size
(
message
)
;
return
ret
;
}
...
...
@@ -915,8 +913,6 @@ nice_turn_socket_parse_recv_message (NiceSocket *sock, NiceSocket **from_sock,
message
->
buffers
[
0
].
buffer
!=
NULL
&&
message
->
buffers
[
1
].
buffer
==
NULL
))
{
/* Fast path. Single massive buffer. */
g_assert_cmpuint
(
message
->
length
,
<=
,
message
->
buffers
[
0
].
size
);
len
=
nice_turn_socket_parse_recv
(
sock
,
from_sock
,
message
->
from
,
message
->
length
,
message
->
buffers
[
0
].
buffer
,
message
->
from
,
message
->
buffers
[
0
].
buffer
,
message
->
length
);
...
...
tests/test-bsd.c
View file @
4f456a46
...
...
@@ -273,7 +273,6 @@ test_multi_message_recv (guint n_sends, guint n_receives,
send_messages
[
i
].
buffers
=
send_bufs
+
i
*
n_bufs_per_message
;
send_messages
[
i
].
n_buffers
=
n_bufs_per_message
;
send_messages
[
i
].
length
=
0
;
}
/* Set up the receive buffers. Yay for dynamic tests! */
...
...
tests/test-send-recv.c
View file @
4f456a46
...
...
@@ -549,12 +549,12 @@ generate_messages_to_transmit (TestIOStreamThreadData *data,
NiceOutputMessage
*
message
=
&
((
*
messages
)[
i
]);
guint
j
;
gsize
max_message_size
;
gsize
message_len
=
0
;
message
->
n_buffers
=
generate_buffer_count
(
test_data
->
transmit
.
buffer_count_strategy
,
test_data
->
transmit_size_rand
,
buffer_offset
);
message
->
buffers
=
g_malloc_n
(
message
->
n_buffers
,
sizeof
(
GOutputVector
));
message
->
length
=
0
;
/* Limit the overall message size to the smaller of (n_bytes / n_messages)
* and MAX_MESSAGE_SIZE, to ensure each message is non-empty. */
...
...
@@ -572,12 +572,12 @@ generate_messages_to_transmit (TestIOStreamThreadData *data,
buf_len
=
MIN
(
buf_len
,
test_data
->
n_bytes
-
test_data
->
transmitted_bytes
-
total_buf_len
);
buf_len
=
MIN
(
buf_len
,
max_message_size
-
message
->
length
);
buf_len
=
MIN
(
buf_len
,
max_message_size
-
message
_len
);
buffer
->
size
=
buf_len
;
buf
=
g_malloc
(
buffer
->
size
);
buffer
->
buffer
=
buf
;
message
->
length
+=
buf_len
;
message
_len
+=
buf_len
;
total_buf_len
+=
buf_len
;
/* Fill it with data. */
...
...
@@ -587,13 +587,13 @@ generate_messages_to_transmit (TestIOStreamThreadData *data,
buffer_offset
+=
buf_len
;
/* Reached the maximum UDP payload size? */
if
(
message
->
length
>=
max_message_size
)
{
if
(
message
_len
>=
max_message_size
)
{
message
->
n_buffers
=
j
+
1
;
break
;
}
}