~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

Viewing changes to lib/kernel/doc/src/gen_udp.xml

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090215164252-q5x4rcf8a5pbesb1
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="latin1" ?>
 
2
<!DOCTYPE erlref SYSTEM "erlref.dtd">
 
3
 
 
4
<erlref>
 
5
  <header>
 
6
    <copyright>
 
7
      <year>1997</year>
 
8
      <year>2007</year>
 
9
      <holder>Ericsson AB, All Rights Reserved</holder>
 
10
    </copyright>
 
11
    <legalnotice>
 
12
  The contents of this file are subject to the Erlang Public License,
 
13
  Version 1.1, (the "License"); you may not use this file except in
 
14
  compliance with the License. You should have received a copy of the
 
15
  Erlang Public License along with this software. If not, it can be
 
16
  retrieved online at http://www.erlang.org/.
 
17
 
 
18
  Software distributed under the License is distributed on an "AS IS"
 
19
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
20
  the License for the specific language governing rights and limitations
 
21
  under the License.
 
22
 
 
23
  The Initial Developer of the Original Code is Ericsson AB.
 
24
    </legalnotice>
 
25
 
 
26
    <title>gen_udp</title>
 
27
    <prepared>tony@erix.ericsson.se</prepared>
 
28
    <docno></docno>
 
29
    <date>1997-12-03</date>
 
30
    <rev>A</rev>
 
31
  </header>
 
32
  <module>gen_udp</module>
 
33
  <modulesummary>Interface to UDP sockets</modulesummary>
 
34
  <description>
 
35
    <p>The <c>gen_udp</c> module provides functions for communicating
 
36
      with sockets using the UDP protocol.</p>
 
37
  </description>
 
38
 
 
39
  <section>
 
40
    <title>DATA TYPES</title>
 
41
    <code type="none">
 
42
ip_address()
 
43
  see inet(3)
 
44
 
 
45
posix()
 
46
  see inet(3)
 
47
 
 
48
socket()
 
49
  as returned by open/1,2</code>
 
50
  </section>
 
51
  <funcs>
 
52
    <func>
 
53
      <name>open(Port) -> {ok, Socket} | {error, Reason}</name>
 
54
      <name>open(Port, Options) -> {ok, Socket} | {error, Reason}</name>
 
55
      <fsummary>Associate a UDP port number with the process calling it</fsummary>
 
56
      <type>
 
57
        <v>Port = 0..65535</v>
 
58
        <v>Options = [Opt]</v>
 
59
        <v>&nbsp;Opt -- see below</v>
 
60
        <v>Socket = socket()</v>
 
61
        <v>Reason = posix()</v>
 
62
      </type>
 
63
      <desc>
 
64
        <p>Associates a UDP port number (<c>Port</c>) with the calling
 
65
          process.</p>
 
66
        <p>The available options are:</p>
 
67
        <taglist>
 
68
          <tag><c>list</c></tag>
 
69
          <item>
 
70
            <p>Received <c>Packet</c> is delivered as a list.</p>
 
71
          </item>
 
72
          <tag><c>binary</c></tag>
 
73
          <item>
 
74
            <p>Received <c>Packet</c> is delivered as a binary.</p>
 
75
          </item>
 
76
          <tag><c>{ip, ip_address()}</c></tag>
 
77
          <item>
 
78
            <p>If the host has several network interfaces, this option
 
79
              specifies which one to use.</p>
 
80
          </item>
 
81
          <tag><c>{fd, int()}</c></tag>
 
82
          <item>
 
83
            <p>If a socket has somehow been opened without using
 
84
              <c>gen_udp</c>, use this option to pass the file
 
85
              descriptor for it.</p>
 
86
          </item>
 
87
          <tag><c>inet6</c></tag>
 
88
          <item>
 
89
            <p>Set up the socket for IPv6.</p>
 
90
          </item>
 
91
          <tag><c>inet</c></tag>
 
92
          <item>
 
93
            <p>Set up the socket for IPv4.</p>
 
94
          </item>
 
95
          <tag><c>Opt</c></tag>
 
96
          <item>
 
97
            <p>See
 
98
              <seealso marker="inet#setopts/2">inet:setopts/2</seealso>.</p>
 
99
          </item>
 
100
        </taglist>
 
101
        <p>The returned socket <c>Socket</c> is used to send packets
 
102
          from this port with <c>send/4</c>. When UDP packets arrive at
 
103
          the opened port, they are delivered as messages:</p>
 
104
        <code type="none">
 
105
{udp, Socket, IP, InPortNo, Packet}</code>
 
106
        <p>Note that arriving UDP packets that are longer than
 
107
          the receive buffer option specifies, might be truncated
 
108
          without warning.</p>
 
109
        <p><c>IP</c> and <c>InPortNo</c> define the address from which
 
110
          <c>Packet</c> came. <c>Packet</c> is a list of bytes if
 
111
          the option <c>list</c> was specified. <c>Packet</c> is a
 
112
          binary if the option <c>binary</c> was specified.</p>
 
113
        <p>Default value for the receive buffer option is
 
114
          <c>{recbuf, 8192}</c>.</p>
 
115
        <p>If <c>Port == 0</c>, the underlying OS assigns a free UDP
 
116
          port, use <c>inet:port/1</c> to retrieve it.</p>
 
117
      </desc>
 
118
    </func>
 
119
    <func>
 
120
      <name>send(Socket, Address, Port, Packet) -> ok | {error, Reason}</name>
 
121
      <fsummary>Send a packet</fsummary>
 
122
      <type>
 
123
        <v>Socket = socket()</v>
 
124
        <v>Address = string() | atom() | ip_address()</v>
 
125
        <v>Port = 0..65535</v>
 
126
        <v>Packet = [char()] | binary()</v>
 
127
        <v>Reason = not_owner | posix()</v>
 
128
      </type>
 
129
      <desc>
 
130
        <p>Sends a packet to the specified address and port.
 
131
          The <c>Address</c> argument can be either a hostname, or an
 
132
          IP address.</p>
 
133
      </desc>
 
134
    </func>
 
135
    <func>
 
136
      <name>recv(Socket, Length) -> {ok, {Address, Port, Packet}} | {error, Reason}</name>
 
137
      <name>recv(Socket, Length, Timeout) -> {ok, {Address, Port, Packet}} | {error, Reason}</name>
 
138
      <fsummary>Receive a packet from a passive socket</fsummary>
 
139
      <type>
 
140
        <v>Socket = socket()</v>
 
141
        <v>Length  = int()</v>
 
142
        <v>Address = ip_address()</v>
 
143
        <v>Port = 0..65535</v>
 
144
        <v>Packet = [char()] | binary()</v>
 
145
        <v>Timeout = int() | infinity</v>
 
146
        <v>Reason = not_owner | posix()</v>
 
147
      </type>
 
148
      <desc>
 
149
        <p>This function receives a packet from a socket in passive
 
150
          mode.</p>
 
151
        <p>The optional <c>Timeout</c> parameter specifies a timeout in
 
152
          milliseconds. The default value is <c>infinity</c>.</p>
 
153
      </desc>
 
154
    </func>
 
155
    <func>
 
156
      <name>controlling_process(Socket, Pid) -> ok</name>
 
157
      <fsummary>Change controlling process of a socket</fsummary>
 
158
      <type>
 
159
        <v>Socket = socket()</v>
 
160
        <v>Pid = pid()</v>
 
161
      </type>
 
162
      <desc>
 
163
        <p>Assigns a new controlling process <c>Pid</c> to
 
164
          <c>Socket</c>. The controlling process is the process which
 
165
          receives messages from the socket.</p>
 
166
      </desc>
 
167
    </func>
 
168
    <func>
 
169
      <name>close(Socket) -> ok | {error, Reason}</name>
 
170
      <fsummary>Close a UDP socket</fsummary>
 
171
      <type>
 
172
        <v>Socket = socket()</v>
 
173
        <v>Reason = not_owner | posix()</v>
 
174
      </type>
 
175
      <desc>
 
176
        <p>Closes a UDP socket.</p>
 
177
      </desc>
 
178
    </func>
 
179
  </funcs>
 
180
</erlref>
 
181