1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
|
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE cref SYSTEM "cref.dtd">
<cref>
<header>
<copyright>
<year>1996</year><year>2016</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
</legalnotice>
<title>erl_connect</title>
<prepared>Torbjörn Törnkvist</prepared>
<responsible>Torbjörn Törnkvist</responsible>
<docno></docno>
<approved>Bjarne Däcker</approved>
<checked>Torbjörn Törnkvist</checked>
<date>1998-07-03</date>
<rev>A</rev>
<file>erl_connect.xml</file>
</header>
<lib>erl_connect</lib>
<libsummary>Communicate with distributed Erlang.</libsummary>
<description>
<p>This module provides support for communication between distributed
Erlang nodes and C-nodes, in a manner that is transparent to Erlang
processes.</p>
<p>A C-node appears to Erlang as a <em>hidden node</em>.
That is, Erlang processes that know the name of the
C-node can communicate with it in a normal manner, but
the node name does not appear in the listing provided by
<seealso marker="erts:erlang#nodes/0"><c>erlang:nodes/0</c></seealso>
in <c>ERTS</c>.</p>
</description>
<funcs>
<func>
<name><ret>int</ret><nametext>erl_accept(listensock, conp)</nametext></name>
<fsummary>Accept a connection.</fsummary>
<marker id="erl_accept"/>
<type>
<v>int listensock;</v>
<v>ErlConnect *conp;</v>
</type>
<desc>
<p>This function is used by a server process to accept a
connection from a client process.</p>
<list type="bulleted">
<item><c><![CDATA[listensock]]></c> is an open socket descriptor on
which <c><![CDATA[listen()]]></c> has previously been called.</item>
<item><c><![CDATA[conp]]></c> is a pointer to an
<c><![CDATA[ErlConnect]]></c> struct, described as follows:</item>
</list>
<code type="none"><![CDATA[
typedef struct {
char ipadr[4];
char nodename[MAXNODELEN];
} ErlConnect;
]]></code>
<p>On success, <c><![CDATA[conp]]></c> is filled in with the address and
node name of the connecting client and a file descriptor is
returned. On failure, <c><![CDATA[ERL_ERROR]]></c> is returned and
<c><![CDATA[erl_errno]]></c> is set to <c><![CDATA[EIO]]></c>.</p>
</desc>
</func>
<func>
<name><ret>int</ret><nametext>erl_close_connection(fd)</nametext></name>
<fsummary>Close a connection to an Erlang node.</fsummary>
<type>
<v>int fd;</v>
</type>
<desc>
<p>Closes an open connection to an Erlang node.</p>
<p><c><![CDATA[Fd]]></c> is a file descriptor obtained from
<c><![CDATA[erl_connect()]]></c> or
<c><![CDATA[erl_xconnect()]]></c>.</p>
<p>Returns <c>0</c> on success. If the call fails, a non-zero value
is returned, and the reason for the error can be obtained with the
appropriate platform-dependent call.</p>
</desc>
</func>
<func>
<name><ret>int</ret><nametext>erl_connect(node)</nametext></name>
<name><ret>int</ret><nametext>erl_xconnect(addr, alive)</nametext></name>
<fsummary>Establish a connection to an Erlang node.</fsummary>
<type>
<v>char *node, *alive;</v>
<v>struct in_addr *addr;</v>
</type>
<desc>
<p>Sets up a connection to an Erlang node.</p>
<p><c><![CDATA[erl_xconnect()]]></c> requires the IP address of the
remote host and the alivename of the remote node to be
specified. <c><![CDATA[erl_connect()]]></c> provides an alternative
interface, and determines the information from the node name
provided.</p>
<list type="bulleted">
<item><c><![CDATA[addr]]></c> is the 32-bit IP address of the remote
host.</item>
<item><c><![CDATA[alive]]></c> is the alivename of the remote node.
</item>
<item><c><![CDATA[node]]></c> is the name of the remote node.</item>
</list>
<p>Returns an open file descriptor on success, otherwise a negative
value. In the latter case <c><![CDATA[erl_errno]]></c> is set to one
of:</p>
<taglist>
<tag><c><![CDATA[EHOSTUNREACH]]></c></tag>
<item>The remote host <c><![CDATA[node]]></c> is unreachable.</item>
<tag><c><![CDATA[ENOMEM]]></c></tag>
<item>No more memory is available.</item>
<tag><c><![CDATA[EIO]]></c></tag>
<item>I/O error.</item>
</taglist>
<p>Also, <c><![CDATA[errno]]></c> values from
<c><![CDATA[socket]]></c><em>(2)</em> and
<c><![CDATA[connect]]></c><em>(2)</em>
system calls can be propagated into <c><![CDATA[erl_errno]]></c>.</p>
<p><em>Example:</em></p>
<code type="none"><![CDATA[
#define NODE "[email protected]"
#define ALIVE "madonna"
#define IP_ADDR "150.236.14.75"
/*** Variant 1 ***/
erl_connect( NODE );
/*** Variant 2 ***/
struct in_addr addr;
addr = inet_addr(IP_ADDR);
erl_xconnect( &addr , ALIVE );
]]></code>
</desc>
</func>
<func>
<name><ret>int</ret><nametext>erl_connect_init(number, cookie, creation)</nametext></name>
<name><ret>int</ret><nametext>erl_connect_xinit(host, alive, node, addr, cookie, creation)</nametext></name>
<fsummary>Initialize communication.</fsummary>
<marker id="erl_connect_init"/>
<type>
<v>int number;</v>
<v>char *cookie;</v>
<v>short creation;</v>
<v>char *host,*alive,*node;</v>
<v>struct in_addr *addr;</v>
</type>
<desc>
<p>Initializes the <c><![CDATA[erl_connect]]></c> module.
In particular, these functions are used to identify the name of the
C-node from which they are called. One of these functions must
be called before any of the other functions in the <c>erl_connect</c>
module are used.</p>
<p><c><![CDATA[erl_connect_xinit()]]></c> stores for later use
information about:</p>
<list type="bulleted">
<item>Hostname of the node, <c><![CDATA[host]]></c></item>
<item>Alivename, <c><![CDATA[alive]]></c></item>
<item>Node name, <c><![CDATA[node]]></c></item>
<item>IP address, <c><![CDATA[addr]]></c></item>
<item>Cookie, <c><![CDATA[cookie]]></c></item>
<item>Creation number, <c><![CDATA[creation]]></c></item>
</list>
<p><c><![CDATA[erl_connect_init()]]></c>
provides an alternative interface that does not require as much
information from the caller. Instead,
<c><![CDATA[erl_connect_init()]]></c>
uses <c><![CDATA[gethostbyname()]]></c> to obtain default values.</p>
<p>If you use <c><![CDATA[erl_connect_init()]]></c>, your node will
have a short name, that is, it will not be fully qualified. If you
need to use fully qualified (long) names, use
<c><![CDATA[erl_connect_xinit()]]></c> instead.</p>
<list type="bulleted">
<item>
<p><c><![CDATA[host]]></c> is the name of the host on which the node
is running.</p>
</item>
<item>
<p><c><![CDATA[alive]]></c> is the alivename of the node.</p>
</item>
<item>
<p><c><![CDATA[node]]></c> is the node name. It is to
be of the form <em>alivename@hostname</em>.</p>
</item>
<item>
<p><c><![CDATA[addr]]></c> is the 32-bit IP address of
<c><![CDATA[host]]></c>.</p>
</item>
<item>
<p><c><![CDATA[cookie]]></c> is the authorization string required
for access to the remote node. If <c>NULL</c>, the user
<c>HOME</c> directory is searched for a cookie file
<c><![CDATA[.erlang.cookie]]></c>. The path to
the home directory is retrieved from environment variable
<c><![CDATA[HOME]]></c> on Unix and from the
<c><![CDATA[HOMEDRIVE]]></c> and
<c><![CDATA[HOMEPATH]]></c> variables on Windows. For more
details, see the <seealso marker="kernel:auth">
<c>kernel:auth</c></seealso> module.</p>
</item>
<item>
<p><c><![CDATA[creation]]></c> helps identifying a particular
instance of a C-node. In particular, it can help prevent us from
receiving messages sent to an earlier process with the same
registered name.</p>
</item>
</list>
<p>A C-node acting as a server is assigned a creation number
when it calls <c><![CDATA[erl_publish()]]></c>.</p>
<p><c><![CDATA[number]]></c> is used by
<c><![CDATA[erl_connect_init()]]></c> to
construct the actual node name. In Example 2
below, <em>"[email protected]"</em> is the resulting node name.</p>
<p><em>Example 1:</em></p>
<code type="none"><![CDATA[
struct in_addr addr;
addr = inet_addr("150.236.14.75");
if (!erl_connect_xinit("chivas",
"madonna",
"[email protected]",
&addr;
"samplecookiestring..."),
0)
erl_err_quit("<ERROR> when initializing !");
]]></code>
<p><em>Example 2:</em></p>
<code type="none"><![CDATA[
if (!erl_connect_init(17, "samplecookiestring...", 0))
erl_err_quit("<ERROR> when initializing !");
]]></code>
</desc>
</func>
<func>
<name><ret>int</ret><nametext>erl_publish(port)</nametext></name>
<fsummary>Publish a node name.</fsummary>
<type>
<v>int port;</v>
</type>
<desc>
<p>This function is used by a server process to register
with the local name server <em>epmd</em>, thereby allowing
other processes to send messages by using the registered name.
Before calling this function, the process should
have called <c><![CDATA[bind()]]></c> and <c><![CDATA[listen()]]></c>
on an open socket.</p>
<p><c><![CDATA[port]]></c> is the local name to register, and is to be
the same as the port number that was previously bound to the
socket.</p>
<p>To unregister with EPMD, simply close the returned descriptor.</p>
<p>On success, a descriptor connecting the calling process to EPMD is
returned. On failure, <c>-1</c> is returned and
<c><![CDATA[erl_errno]]></c> is set to:</p>
<taglist>
<tag><c><![CDATA[EIO]]></c></tag>
<item>I/O error.</item>
</taglist>
<p>Also, <c><![CDATA[errno]]></c> values from
<c><![CDATA[socket]]></c><em>(2)</em>
and <c><![CDATA[connect]]></c><em>(2)</em> system calls can be
propagated into <c><![CDATA[erl_errno]]></c>.</p>
</desc>
</func>
<func>
<name><ret>int</ret><nametext>erl_receive(fd, bufp, bufsize)</nametext></name>
<fsummary>Receive a message.</fsummary>
<marker id="erl_receive"/>
<type>
<v>int fd;</v>
<v>char *bufp;</v>
<v>int bufsize;</v>
</type>
<desc>
<p>Receives a message consisting of a sequence
of bytes in the Erlang external format.</p>
<list type="bulleted">
<item><c><![CDATA[fd]]></c> is an open descriptor to an Erlang
connection.</item>
<item><c><![CDATA[bufp]]></c> is a buffer large enough to hold the
expected message.</item>
<item><c><![CDATA[bufsize]]></c> indicates the size of
<c><![CDATA[bufp]]></c>.</item>
</list>
<p>If a <em>tick</em> occurs, that is, the Erlang node on the
other end of the connection has polled this node to see if it
is still alive, the function returns <c><![CDATA[ERL_TICK]]></c> and
no message is placed in the buffer. Also,
<c><![CDATA[erl_errno]]></c> is set to <c><![CDATA[EAGAIN]]></c>.</p>
<p>On success, the message is placed in the specified buffer
and the function returns the number of bytes actually read. On
failure, the function returns a negative value and sets
<c><![CDATA[erl_errno]]></c> to one of:</p>
<taglist>
<tag><c><![CDATA[EAGAIN]]></c></tag>
<item>Temporary error: Try again.</item>
<tag><c><![CDATA[EMSGSIZE]]></c></tag>
<item>Buffer is too small.</item>
<tag><c><![CDATA[EIO]]></c></tag>
<item>I/O error.</item>
</taglist>
</desc>
</func>
<func>
<name><ret>int</ret><nametext>erl_receive_msg(fd, bufp, bufsize, emsg)</nametext></name>
<fsummary>Receive and decode a message.</fsummary>
<marker id="erl_receive_msg"/>
<type>
<v>int fd;</v>
<v>unsigned char *bufp;</v>
<v>int bufsize;</v>
<v>ErlMessage *emsg;</v>
</type>
<desc>
<p>Receives the message into the specified buffer
and decodes into <c><![CDATA[(ErlMessage *) emsg]]></c>.</p>
<list type="bulleted">
<item><c><![CDATA[fd]]></c> is an open descriptor to an Erlang
connection.</item>
<item><c><![CDATA[bufp]]></c> is a buffer large enough to hold the
expected message.</item>
<item><c><![CDATA[bufsize]]></c> indicates the size of
<c><![CDATA[bufp]]></c>.</item>
<item>><c><![CDATA[emsg]]></c> is a pointer to an
<c><![CDATA[ErlMessage]]></c> structure
into which the message will be decoded.
<c><![CDATA[ErlMessage]]></c> is defined as follows:</item>
</list>
<code type="none"><![CDATA[
typedef struct {
int type;
ETERM *msg;
ETERM *to;
ETERM *from;
char to_name[MAXREGLEN];
} ErlMessage;
]]></code>
<note>
<p>The definition of <c><![CDATA[ErlMessage]]></c> has changed since
earlier versions of <c>Erl_Interface</c>.</p>
</note>
<p><c><![CDATA[type]]></c> identifies the type of message, one of the
following:</p>
<taglist>
<tag><c><![CDATA[ERL_SEND]]></c></tag>
<item>
<p>An ordinary send operation has occurred and
<c><![CDATA[emsg->to]]></c> contains the pid of the recipient.
The message is in <c><![CDATA[emsg->msg]]></c>.</p>
</item>
<tag><c><![CDATA[ERL_REG_SEND]]></c></tag>
<item>
<p>A registered send operation has occurred and
<c><![CDATA[emsg->from]]></c> contains the pid of the sender.
The message is in <c><![CDATA[emsg->msg]]></c>.</p>
</item>
<tag><c><![CDATA[ERL_LINK]]></c> or <c><![CDATA[ERL_UNLINK]]></c>
</tag>
<item>
<p><c><![CDATA[emsg->to]]></c> and <c><![CDATA[emsg->from]]></c>
contain the pids of the sender and recipient of the link or
unlink. <c><![CDATA[emsg->msg]]></c> is not used.</p>
</item>
<tag><c><![CDATA[ERL_EXIT]]></c></tag>
<item>
<p>A link is broken. <c><![CDATA[emsg->to]]></c> and
<c><![CDATA[emsg->from]]></c> contain the pids of the linked
processes, and <c><![CDATA[emsg->msg]]></c> contains the reason
for the exit.</p>
</item>
</taglist>
<note>
<p>It is the caller's responsibility to release the
memory pointed to by <c><![CDATA[emsg->msg]]></c>,
<c><![CDATA[emsg->to]]></c>, and
<c><![CDATA[emsg->from]]></c>.</p>
</note>
<p>If a <em>tick</em> occurs, that is, the Erlang node on the
other end of the connection has polled this node to see if it
is still alive, the function returns <c><![CDATA[ERL_TICK]]></c>
indicating that the tick has been received and responded to,
but no message is placed in the buffer. In this case you
are to call <c><![CDATA[erl_receive_msg()]]></c> again.</p>
<p>On success, the function returns <c><![CDATA[ERL_MSG]]></c> and the
<c><![CDATA[Emsg]]></c> struct is initialized as described above, or
<c><![CDATA[ERL_TICK]]></c>, in which case no message is returned. On
failure, the function returns <c><![CDATA[ERL_ERROR]]></c> and sets
<c><![CDATA[erl_errno]]></c> to one of:</p>
<taglist>
<tag><c><![CDATA[EMSGSIZE]]></c></tag>
<item>Buffer is too small.</item>
<tag><c><![CDATA[ENOMEM]]></c></tag>
<item>No more memory is available.</item>
<tag><c><![CDATA[EIO]]></c></tag>
<item>I/O error.</item>
</taglist>
</desc>
</func>
<func>
<name><ret>int</ret><nametext>erl_reg_send(fd, to, msg)</nametext></name>
<fsummary>Send a message to a registered name.</fsummary>
<marker id="erl_reg_send"/>
<type>
<v>int fd;</v>
<v>char *to;</v>
<v>ETERM *msg;</v>
</type>
<desc>
<p>Sends an Erlang term to a registered process.</p>
<list type="bulleted">
<item><c><![CDATA[fd]]></c> is an open descriptor to an Erlang
connection.</item>
<item><c><![CDATA[to]]></c> is a string containing the registered name
of the intended recipient of the message.</item>
<item><c><![CDATA[msg]]></c> is the Erlang term to be sent.</item>
</list>
<p>Returns <c>1</c> on success, otherwise <c>0</c>. In
the latter case <c><![CDATA[erl_errno]]></c> is set to one of:</p>
<taglist>
<tag><c><![CDATA[ENOMEM]]></c></tag>
<item>No more memory is available.</item>
<tag><c><![CDATA[EIO]]></c></tag>
<item>I/O error.</item>
</taglist>
</desc>
</func>
<func>
<name><ret>ETERM *</ret><nametext>erl_rpc(fd, mod, fun, args)</nametext></name>
<name><ret>int</ret><nametext>erl_rpc_from(fd, timeout, emsg)</nametext></name>
<name><ret>int</ret><nametext>erl_rpc_to(fd, mod, fun, args)</nametext></name>
<fsummary>Remote Procedure Call.</fsummary>
<type>
<v>int fd, timeout;</v>
<v>char *mod, *fun;</v>
<v>ETERM *args;</v>
<v>ErlMessage *emsg;</v>
</type>
<desc>
<p>Supports calling Erlang functions on remote nodes.
<c><![CDATA[erl_rpc_to()]]></c> sends an RPC request to a remote node
and <c><![CDATA[erl_rpc_from()]]></c> receives the results of such a
call. <c><![CDATA[erl_rpc()]]></c> combines the functionality of
these two functions by sending an RPC request and waiting for the
results. See also <seealso marker="kernel:rpc#call/4">
<c>rpc:call/4</c></seealso> in <c>Kernel</c>.</p>
<list type="bulleted">
<item><c><![CDATA[fd]]></c> is an open descriptor to an Erlang
connection.</item>
<item><c><![CDATA[timeout]]></c> is the maximum time (in milliseconds)
to wait for
results. To wait forever, specify <c><![CDATA[ERL_NO_TIMEOUT]]></c>.
When <c>erl_rpc()</c> calls <c>erl_rpc_from()</c>, the call will
never timeout.</item>
<item><c><![CDATA[mod]]></c> is the name of the module containing the
function to be run on the remote node.</item>
<item><c><![CDATA[fun]]></c> is the name of the function to run.
</item>
<item><c><![CDATA[args]]></c> is an Erlang list, containing the
arguments to be passed to the function.</item>
<item><c><![CDATA[emsg]]></c> is a message containing the result of
the function call.</item>
</list>
<p>The actual message returned by the RPC server
is a 2-tuple <c><![CDATA[{rex,Reply}]]></c>. If you use
<c><![CDATA[erl_rpc_from()]]></c> in your code, this is the message
you will need to parse. If you use <c><![CDATA[erl_rpc()]]></c>, the
tuple itself is parsed for you, and the message returned to your
program is the Erlang term containing <c><![CDATA[Reply]]></c> only.
Replies to RPC requests are always <c>ERL_SEND</c> messages.</p>
<note>
<p>It is the caller's responsibility to free the returned
<c><![CDATA[ETERM]]></c> structure and the memory pointed to by
<c><![CDATA[emsg->msg]]></c> and <c><![CDATA[emsg->to]]></c>.</p>
</note>
<p><c><![CDATA[erl_rpc()]]></c> returns the remote function's return
value on success, otherwise <c><![CDATA[NULL]]></c>.</p>
<p><c><![CDATA[erl_rpc_to()]]></c> returns <c>0</c> on
success, otherwise a negative number.</p>
<p><c><![CDATA[erl_rcp_from()]]></c> returns <c><![CDATA[ERL_MSG]]></c>
on success (with <c><![CDATA[Emsg]]></c> now
containing the reply tuple), otherwise one of
<c><![CDATA[ERL_TICK]]></c>, <c><![CDATA[ERL_TIMEOUT]]></c>, or
<c><![CDATA[ERL_ERROR]]></c>.</p>
<p>When failing,
all three functions set <c><![CDATA[erl_errno]]></c> to one of:</p>
<taglist>
<tag><c><![CDATA[ENOMEM]]></c></tag>
<item>No more memory is available.</item>
<tag><c><![CDATA[EIO]]></c></tag>
<item>I/O error.</item>
<tag><c><![CDATA[ETIMEDOUT]]></c></tag>
<item>Timeout has expired.</item>
<tag><c><![CDATA[EAGAIN]]></c></tag>
<item>Temporary error: Try again.</item>
</taglist>
</desc>
</func>
<func>
<name><ret>int</ret><nametext>erl_send(fd, to, msg)</nametext></name>
<fsummary>Send a message.</fsummary>
<marker id="erl_send"/>
<type>
<v>int fd;</v>
<v>ETERM *to, *msg;</v>
</type>
<desc>
<p>Sends an Erlang term to a process.</p>
<list type="bulleted">
<item><c><![CDATA[fd]]></c> is an open descriptor to an Erlang
connection.</item>
<item><c><![CDATA[to]]></c> is an Erlang term containing the pid of
the intended recipient of the message.</item>
<item>><c><![CDATA[msg]]></c> is the Erlang term to be sent.</item>
</list>
<p>Returns <c>1</c> on success, otherwise <c>0</c>. In
the latter case <c><![CDATA[erl_errno]]></c> is set to one of:</p>
<taglist>
<tag><c><![CDATA[EINVAL]]></c></tag>
<item>Invalid argument: <c><![CDATA[to]]></c> is not a valid Erlang
pid.</item>
<tag><c><![CDATA[ENOMEM]]></c></tag>
<item>No more memory is available.</item>
<tag><c><![CDATA[EIO]]></c></tag>
<item>I/O error.</item>
</taglist>
</desc>
</func>
<func>
<name><ret>const char *</ret><nametext>erl_thisalivename()</nametext></name>
<name><ret>const char *</ret><nametext>erl_thiscookie()</nametext></name>
<name><ret>short</ret><nametext>erl_thiscreation()</nametext></name>
<name><ret>const char *</ret><nametext>erl_thishostname()</nametext></name>
<name><ret>const char *</ret><nametext>erl_thisnodename()</nametext></name>
<fsummary>Retrieve some values.</fsummary>
<desc>
<p>Retrieves information about
the C-node. These values are initially set with
<c><![CDATA[erl_connect_init()]]></c> or
<c><![CDATA[erl_connect_xinit()]]></c>.</p>
</desc>
</func>
<func>
<name><ret>int</ret><nametext>erl_unpublish(alive)</nametext></name>
<fsummary>Forcefully unpublish a node name.</fsummary>
<type>
<v>char *alive;</v>
</type>
<desc>
<p>This function can be called by a process to unregister a
specified node from EPMD on the local host. This is, however, usually
not allowed, unless EPMD was started with flag
<c>-relaxed_command_check</c>, which it normally is not.</p>
<p>To unregister a node you have published, you should instead
close the descriptor that was returned by
<c><![CDATA[ei_publish()]]></c>.</p>
<warning>
<p>This function is deprecated and will be removed in a future
release.</p>
</warning>
<p><c><![CDATA[alive]]></c> is the name of the node to unregister, that
is, the first component of the node name, without
<c><![CDATA[@hostname]]></c>.</p>
<p>If the node was successfully unregistered from EPMD, <c>0</c> is
returned, otherwise <c>-1</c> is returned and
<c><![CDATA[erl_errno]]></c> is set to <c><![CDATA[EIO]]></c>.</p>
</desc>
</func>
<func>
<name><ret>int</ret><nametext>erl_xreceive_msg(fd, bufpp, bufsizep, emsg)</nametext></name>
<fsummary>Receive and decode a message.</fsummary>
<type>
<v>int fd;</v>
<v>unsigned char **bufpp;</v>
<v>int *bufsizep;</v>
<v>ErlMessage *emsg;</v>
</type>
<desc>
<p>Similar to <c><![CDATA[erl_receive_msg]]></c>. The difference is
that <c><![CDATA[erl_xreceive_msg]]></c> expects the buffer to
have been allocated by <c><![CDATA[malloc]]></c>, and reallocates it
if the received
message does not fit into the original buffer. Therefore
both buffer and buffer length are given as pointers; their values
can change by the call.</p>
<p>On success, the function returns <c><![CDATA[ERL_MSG]]></c> and the
<c><![CDATA[Emsg]]></c> struct is initialized as described above, or
<c><![CDATA[ERL_TICK]]></c>, in which case no message is returned. On
failure, the function returns <c><![CDATA[ERL_ERROR]]></c> and sets
<c><![CDATA[erl_errno]]></c> to one of:</p>
<taglist>
<tag><c><![CDATA[EMSGSIZE]]></c></tag>
<item>Buffer is too small.</item>
<tag><c><![CDATA[ENOMEM]]></c></tag>
<item>No more memory is available.</item>
<tag><c><![CDATA[EIO]]></c></tag>
<item>I/O error.</item>
</taglist>
</desc>
</func>
<func>
<name><ret>struct hostent</ret><nametext>*erl_gethostbyaddr(addr, length, type)</nametext></name>
<name><ret>struct hostent</ret><nametext>*erl_gethostbyaddr_r(addr, length, type, hostp, buffer, buflen, h_errnop)</nametext></name>
<name><ret>struct hostent</ret><nametext>*erl_gethostbyname(name)</nametext></name>
<name><ret>struct hostent</ret><nametext>*erl_gethostbyname_r(name, hostp, buffer, buflen, h_errnop)</nametext></name>
<fsummary>Name lookup functions.</fsummary>
<type>
<v>const char *name;</v>
<v>const char *addr;</v>
<v>int length;</v>
<v>int type;</v>
<v>struct hostent *hostp;</v>
<v>char *buffer;</v>
<v>int buflen;</v>
<v>int *h_errnop;</v>
</type>
<desc>
<p>Convenience functions for some common name lookup functions.</p>
</desc>
</func>
</funcs>
<section>
<title>Debug Information</title>
<p>If a connection attempt fails, the following can be checked:</p>
<list type="bulleted">
<item><c><![CDATA[erl_errno]]></c></item>
<item>That the correct cookie was used</item>
<item>That EPMD is running</item>
<item>That the remote Erlang node on the other side is running the same
version of Erlang as the <c><![CDATA[erl_interface]]></c> library</item>
</list>
</section>
</cref>
|