~ubuntu-branches/debian/stretch/libnice/stretch

« back to all changes in this revision

Viewing changes to socket/socket.c

  • Committer: Package Import Robot
  • Author(s): Simon McVittie
  • Date: 2014-05-14 12:00:13 UTC
  • mfrom: (1.2.9) (5.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20140514120013-fi5mh9bexrjnwnd8
Tags: 0.1.7-1
* New upstream release 0.1.6, 0.1.7
  - fixes various compiler warnings that were mistakenly fatal in 0.1.5
    (Closes: #743232, #743233)
  - update symbols file for new API
* Explicitly disable -Werror, even if we package a non-release in future
* Don't run tests during the build. We were ignoring failures already,
  and they sometimes hang until the buildd terminates them.
  Upstream (Olivier Crête) says they are stable enough to be useful
  for developers, but not for integration testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
#include "socket.h"
44
44
 
45
45
 
46
 
gint
47
 
nice_socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf)
48
 
{
49
 
  return sock->recv (sock, from, len, buf);
50
 
}
51
 
 
52
 
gboolean
53
 
nice_socket_send (NiceSocket *sock, const NiceAddress *to,
54
 
    guint len, const gchar *buf)
55
 
{
56
 
  return sock->send (sock, to, len, buf);
 
46
/**
 
47
 * nice_socket_recv_messages:
 
48
 * @sock: a #NiceSocket
 
49
 * @recv_messages: (array length=n_recv_messages) (out caller-allocates):
 
50
 * array of #NiceInputMessages to return received messages in
 
51
 * @n_recv_messages: number of elements in the @recv_messages array
 
52
 *
 
53
 * Receive up to @n_recv_messages message on the socket, in a non-reliable,
 
54
 * non-blocking fashion. The total size of the buffers in each #NiceInputMessage
 
55
 * must be big enough to contain an entire message (65536 bytes), or excess
 
56
 * bytes will be silently dropped.
 
57
 *
 
58
 * On success, the number of messages received into @recv_messages is returned,
 
59
 * which may be less than @n_recv_messages if the call would have blocked
 
60
 * part-way through. If the socket would have blocked to begin with, or if
 
61
 * @n_recv_messages is zero, zero is returned. On failure, a negative value is
 
62
 * returned, but no further error information is available. Calling this
 
63
 * function on a socket which has closed is an error, and a negative value is
 
64
 * returned.
 
65
 *
 
66
 * If a positive N is returned, the first N messages in @recv_messages are
 
67
 * valid. Each valid message is guaranteed to have a non-zero
 
68
 * #NiceInputMessage::length, and its buffers are guaranteed to be filled
 
69
 * sequentially up to that number of bytes  If #NiceInputMessage::from was
 
70
 * non-%NULL for a valid message, it may be set to the address of the sender of
 
71
 * that received message.
 
72
 *
 
73
 * If the return value is zero or negative, the from return address and length
 
74
 * in every #NiceInputMessage in @recv_messages are guaranteed to be unmodified.
 
75
 * The buffers may have been modified.
 
76
 *
 
77
 * The base addresses and sizes of the buffers in a #NiceInputMessage are never
 
78
 * modified. Neither is the base address of #NiceInputMessage::from, nor the
 
79
 * base address and length of the #NiceInputMessage::buffers array.
 
80
 *
 
81
 * Returns: number of valid messages returned in @recv_messages, or a negative
 
82
 * value on error
 
83
 *
 
84
 * Since: 0.1.5
 
85
 */
 
86
gint
 
87
nice_socket_recv_messages (NiceSocket *sock,
 
88
    NiceInputMessage *recv_messages, guint n_recv_messages)
 
89
{
 
90
  g_return_val_if_fail (sock != NULL, -1);
 
91
  g_return_val_if_fail (n_recv_messages == 0 || recv_messages != NULL, -1);
 
92
 
 
93
  return sock->recv_messages (sock, recv_messages, n_recv_messages);
 
94
}
 
95
 
 
96
/**
 
97
 * nice_socket_send_messages:
 
98
 * @sock: a #NiceSocket
 
99
 * @messages: (array length=n_messages) (in caller-allocates):
 
100
 * array of #NiceOutputMessages containing the messages to send
 
101
 * @n_messages: number of elements in the @messages array
 
102
 *
 
103
 * Send up to @n_messages on the socket, in a non-reliable, non-blocking
 
104
 * fashion. The total size of the buffers in each #NiceOutputMessage
 
105
 * must be at most the maximum UDP payload size (65535 bytes), or excess
 
106
 * bytes will be silently dropped.
 
107
 *
 
108
 * On success, the number of messages transmitted from @messages is returned,
 
109
 * which may be less than @n_messages if the call would have blocked
 
110
 * part-way through. If the socket would have blocked to begin with, or if
 
111
 * @n_messages is zero, zero is returned. On failure, a negative value is
 
112
 * returned, but no further error information is available. Calling this
 
113
 * function on a socket which has closed is an error, and a negative value is
 
114
 * returned.
 
115
 *
 
116
 * If a positive N is returned, the first N messages in @messages have been
 
117
 * sent in full, and the remaining messages have not been sent at all.
 
118
 *
 
119
 * If #NiceOutputMessage::to is specified for a message, that will be used as
 
120
 * the destination address for the message. Otherwise, if %NULL, the default
 
121
 * destination for @sock will be used.
 
122
 *
 
123
 * Every field of every #NiceOutputMessage is guaranteed to be unmodified when
 
124
 * this function returns.
 
125
 *
 
126
 * Returns: number of messages successfully sent from @messages, or a negative
 
127
 * value on error
 
128
 *
 
129
 * Since: 0.1.5
 
130
 */
 
131
gint
 
132
nice_socket_send_messages (NiceSocket *sock, const NiceAddress *to,
 
133
    const NiceOutputMessage *messages, guint n_messages)
 
134
{
 
135
  g_return_val_if_fail (sock != NULL, -1);
 
136
  g_return_val_if_fail (n_messages == 0 || messages != NULL, -1);
 
137
 
 
138
  return sock->send_messages (sock, to, messages, n_messages);
 
139
}
 
140
 
 
141
/* Convenience wrapper around nice_socket_send_messages(). Returns the number of
 
142
 * bytes sent on success (which will be @len), zero if sending would block, or
 
143
 * -1 on error. */
 
144
gssize
 
145
nice_socket_send (NiceSocket *sock, const NiceAddress *to, gsize len,
 
146
    const gchar *buf)
 
147
{
 
148
  GOutputVector local_buf = { buf, len };
 
149
  NiceOutputMessage local_message = { &local_buf, 1};
 
150
  gint ret;
 
151
 
 
152
  ret = sock->send_messages (sock, to, &local_message, 1);
 
153
  if (ret == 1)
 
154
    return len;
 
155
  return ret;
57
156
}
58
157
 
59
158
gboolean
70
169
    g_slice_free (NiceSocket,sock);
71
170
  }
72
171
}
73