mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-03-26 01:42:09 +01:00
259 lines
7.0 KiB
XML
259 lines
7.0 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: da9d81816187b87c03a6cd92a3c3b833f039485c Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
|
|
<refentry xml:id="eventbufferevent.connecthost" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>EventBufferEvent::connectHost</refname>
|
|
<refpurpose>Connexion à un hôte</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<modifier>public</modifier>
|
|
<type>bool</type>
|
|
<methodname>EventBufferEvent::connectHost</methodname>
|
|
<methodparam>
|
|
<type>EventDnsBase</type>
|
|
<parameter>dns_base</parameter>
|
|
</methodparam>
|
|
<methodparam>
|
|
<type>string</type>
|
|
<parameter>hostname</parameter>
|
|
</methodparam>
|
|
<methodparam>
|
|
<type>int</type>
|
|
<parameter>port</parameter>
|
|
</methodparam>
|
|
<methodparam
|
|
choice="opt">
|
|
<type>int</type>
|
|
<parameter>family</parameter>
|
|
<initializer>EventUtil::AF_UNSPEC</initializer>
|
|
</methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Résout le nom d'hôte DNS, recherche de l'adresse du type
|
|
<parameter>family</parameter> (constante <literal>EventUtil::AF_*</literal>).
|
|
Si la résolution du nom échoue, la fonction de rappel de l'événement
|
|
sera appelé avec un événement d'erreur. Si la résolution réussit,
|
|
une tentative de connexion sera émise, tout comme le fait la méthode
|
|
<methodname>EventBufferEvent::connect</methodname>.
|
|
</para>
|
|
<para>
|
|
Le paramètre <parameter>dns_base</parameter> est optionnel.
|
|
Il peut valoir &null;, ou bien un objet créé avec la méthode
|
|
<methodname>EventDnsBase::__construct</methodname>.
|
|
Pour une résolution de nom d'hôte asynchrone, passez une ressource
|
|
d'événement de base DNS valide. Sinon, la résolution du nom d'hôte
|
|
sera bloquante.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
<classname>EventDnsBase</classname> n'est disponible que si
|
|
<literal>Event</literal> est configuré avec l'option
|
|
<option role="configure">--with-event-extra</option>
|
|
(bibliothèque <literal>event_extra</literal>,
|
|
<emphasis>le support des fonctionnalités spécifiques à libevent
|
|
incluant HTTP, DNS et RPC</emphasis>).
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<para>
|
|
<methodname>EventBufferEvent::connectHost</methodname>
|
|
requiert <literal>libevent-2.0.3-alpha</literal> ou suivants.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term>
|
|
<parameter>dns_base</parameter>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
Objet <classname>EventDnsBase</classname> dans le cas
|
|
où le DNS doit être résolu de façon asynchrone. Sinon, &null;.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>
|
|
<parameter>hostname</parameter>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
Le nom d'hôte sur lequel la connexion tente d'être faite.
|
|
Les formats reconnus sont :
|
|
<screen>
|
|
<![CDATA[
|
|
www.example.com (hostname)
|
|
1.2.3.4 (ipv4address)
|
|
::1 (ipv6address)
|
|
[::1] ([ipv6address])
|
|
]]>
|
|
</screen>
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>
|
|
<parameter>port</parameter>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
Le numéro du port
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>
|
|
<parameter>family</parameter>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
Famille de l'adresse.
|
|
<constant>EventUtil::AF_UNSPEC</constant>,
|
|
<constant>EventUtil::AF_INET</constant> ou
|
|
<constant>EventUtil::AF_INET6</constant>. Voir les
|
|
<link linkend="eventutil.constants">constantes EventUtil</link>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
&return.success;
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<example>
|
|
<title>Exemple avec <function>EventBufferEvent::connectHost</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
/* Fonction de rappel de lecture */
|
|
function readcb($bev, $base) {
|
|
//$input = $bev->input; //$bev->getInput();
|
|
|
|
//$pos = $input->search("TTP");
|
|
$pos = $bev->input->search("TTP");
|
|
|
|
while (($n = $bev->input->remove($buf, 1024)) > 0) {
|
|
echo $buf;
|
|
}
|
|
}
|
|
|
|
/* Fonction de rappel de l'événement */
|
|
function eventcb($bev, $events, $base) {
|
|
if ($events & EventBufferEvent::CONNECTED) {
|
|
echo "Connecté.\n";
|
|
} elseif ($events & (EventBufferEvent::ERROR | EventBufferEvent::EOF)) {
|
|
if ($events & EventBufferEvent::ERROR) {
|
|
echo "Erreur DNS : ", $bev->getDnsErrorString(), PHP_EOL;
|
|
}
|
|
|
|
echo "Fermeture\n";
|
|
$base->exit();
|
|
exit("Fait !\n");
|
|
}
|
|
}
|
|
|
|
$base = new EventBase();
|
|
|
|
$dns_base = new EventDnsBase($base, TRUE); // Résolution DNS asynchrone
|
|
if (!$dns_base) {
|
|
exit("Echec de l'initialisation de la base DNS\n");
|
|
}
|
|
|
|
$bev = new EventBufferEvent($base, /* utilisation d'un socket interne */ NULL,
|
|
EventBufferEvent::OPT_CLOSE_ON_FREE | EventBufferEvent::OPT_DEFER_CALLBACKS,
|
|
"readcb", /* writecb */ NULL, "eventcb", $base
|
|
);
|
|
if (!$bev) {
|
|
exit("Echec lors de la création du socket bufferevent\n");
|
|
}
|
|
|
|
//$bev->setCallbacks("readcb", /* writecb */ NULL, "eventcb", $base);
|
|
$bev->enable(Event::READ | Event::WRITE);
|
|
|
|
$output = $bev->output; //$bev->getOutput();
|
|
if (!$output->add(
|
|
"GET {$argv[2]} HTTP/1.0\r\n".
|
|
"Host: {$argv[1]}\r\n".
|
|
"Connection: Close\r\n\r\n"
|
|
)) {
|
|
exit("Echec lors de l'ajout de la demande dans le tampon de sortie\n");
|
|
}
|
|
|
|
if (!$bev->connectHost($dns_base, $argv[1], 80, EventUtil::AF_UNSPEC)) {
|
|
exit("Impossible de se connecter à l'hôte {$argv[1]}\n");
|
|
}
|
|
|
|
$base->dispatch();
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
Connecté.
|
|
HTTP/1.0 301 Moved Permanently
|
|
Location: http://www.google.co.uk/
|
|
Content-Type: text/html; charset=UTF-8
|
|
Date: Sat, 09 Mar 2013 12:21:19 GMT
|
|
Expires: Mon, 08 Apr 2013 12:21:19 GMT
|
|
Cache-Control: public, max-age=2592000
|
|
Server: gws
|
|
Content-Length: 221
|
|
X-XSS-Protection: 1; mode=block
|
|
X-Frame-Options: SAMEORIGIN
|
|
|
|
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
|
|
<TITLE>301 Moved</TITLE></HEAD><BODY>
|
|
<H1>301 Moved</H1>
|
|
The document has moved
|
|
<A HREF="http://www.google.co.uk/">here</A>.
|
|
</BODY></HTML>
|
|
Fermeture
|
|
Fait !
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<simplelist>
|
|
<member>
|
|
<methodname>EventBufferEvent::connect</methodname>
|
|
</member>
|
|
</simplelist>
|
|
</refsect1>
|
|
</refentry>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|