⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileio-sockets.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
字号:
<!-- Copyright (C) 2003 Red Hat, Inc.                                --><!-- This material may be distributed only subject to the terms      --><!-- and conditions set forth in the Open Publication License, v1.0  --><!-- or later (the latest version is presently available at          --><!-- http://www.opencontent.org/openpub/).                           --><!-- Distribution of the work or derivative of the work in any       --><!-- standard (paper) book form is prohibited unless prior           --><!-- permission is obtained from the copyright holder.               --><HTML><HEAD><TITLE>Sockets</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="File System Support Infrastructure"HREF="fileio.html"><LINKREL="PREVIOUS"TITLE="Initialization and Mounting"HREF="fileio-mounting.html"><LINKREL="NEXT"TITLE="Select"HREF="fileio-select.html"></HEAD><BODYCLASS="CHAPTER"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="fileio-mounting.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="fileio-select.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="CHAPTER"><H1><ANAME="FILEIO-SOCKETS">Chapter 26. Sockets</H1><P>If a network stack is present, then the FILEIO infrastructure alsoprovides access to the standard BSD socket calls.</P><P>The netstack table contains entries which describe the networkprotocol stacks that are in the system image. Each resident stackshould export an entry to this table using the<TTCLASS="LITERAL">NSTAB_ENTRY()</TT> macro.</P><P>Each table entry has the following structure:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">struct cyg_nstab_entry{    cyg_bool            valid;          // true if stack initialized    cyg_uint32          syncmode;       // synchronization protocol    char                *name;          // stack name    char                *devname;       // hardware device name    CYG_ADDRWORD        data;           // private data value    int     (*init)( cyg_nstab_entry *nste );    int     (*socket)( cyg_nstab_entry *nste, int domain, int type,		       int protocol, cyg_file *file );};</PRE></TD></TR></TABLE><P>This table is analogous to a combination of the filesystem and mounttables.</P><P>The <TTCLASS="STRUCTFIELD"><I>valid</I></TT> field is set<TTCLASS="LITERAL">true</TT> if the stack's <TTCLASS="FUNCTION">init()</TT>function returned successfully and the<TTCLASS="STRUCTFIELD"><I>syncmode</I></TT> field contains the<TTCLASS="LITERAL">CYG_SYNCMODE_SOCK_*</TT> bits described above.</P><P>The <TTCLASS="STRUCTFIELD"><I>name</I></TT> field contains the name of theprotocol stack.</P><P>The <TTCLASS="STRUCTFIELD"><I>devname</I></TT> field names the device that the stack is using. This mayreference a device under &quot;/dev&quot;, or may be a name that is onlymeaningful to the stack itself.</P><P>The <TTCLASS="FUNCTION">init()</TT> function pointer is called duringsystem initialization to start the protocol stack running. If itreturns non-zero the <TTCLASS="STRUCTFIELD"><I>valid</I></TT> field is setfalse and the stack will be ignored subsequently.</P><P>The <TTCLASS="FUNCTION">socket()</TT> function is called to attempt to create a socket in thestack. When the <TTCLASS="FUNCTION">socket()</TT> API function is called the netstack table isscanned and for each valid entry the <TTCLASS="FUNCTION">socket()</TT>function pointer is called. Ifthis returns non-zero then the scan continues to the next valid stack,or terminates with an error if the end of the table is reached.</P><P>The result of a successful socket call is an initialized file objectwith the <TTCLASS="STRUCTFIELD"><I>f_xops</I></TT> field pointing to thefollowing structure:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">struct cyg_sock_ops{    int (*bind)      ( cyg_file *fp, const sockaddr *sa, socklen_t len );    int (*connect)   ( cyg_file *fp, const sockaddr *sa, socklen_t len );    int (*accept)    ( cyg_file *fp, cyg_file *new_fp,                       struct sockaddr *name, socklen_t *anamelen );    int (*listen)    ( cyg_file *fp, int len );    int (*getname)   ( cyg_file *fp, sockaddr *sa, socklen_t *len, int peer );    int (*shutdown)  ( cyg_file *fp, int flags );    int (*getsockopt)( cyg_file *fp, int level, int optname,                       void *optval, socklen_t *optlen);    int (*setsockopt)( cyg_file *fp, int level, int optname,                       const void *optval, socklen_t optlen);    int (*sendmsg)   ( cyg_file *fp, const struct msghdr *m,                       int flags, ssize_t *retsize );    int (*recvmsg)   ( cyg_file *fp, struct msghdr *m,                       socklen_t *namelen, ssize_t *retsize );};</PRE></TD></TR></TABLE><P>It should be obvious from the names of these functions which API callsthey provide support for. The <TTCLASS="FUNCTION">getname()</TT> functionpointer provides support for both <TTCLASS="FUNCTION">getsockname()</TT>and <TTCLASS="FUNCTION">getpeername()</TT> while the<TTCLASS="FUNCTION">sendmsg()</TT> and <TTCLASS="FUNCTION">recvmsg()</TT>function pointers provide support for <TTCLASS="FUNCTION">send()</TT>,<TTCLASS="FUNCTION">sendto()</TT>, <TTCLASS="FUNCTION">sendmsg()</TT>,<TTCLASS="FUNCTION">recv()</TT>, <TTCLASS="FUNCTION">recvfrom()</TT> and<TTCLASS="FUNCTION">recvmsg()</TT> as appropriate.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="fileio-mounting.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="fileio-select.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Initialization and Mounting</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="fileio.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Select</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -