]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - apps/tidep0084.git/blob - tutorials/generic_sensor_tutorial/final/SensorToCloud/components/common/src/stream_socket_private.h
Added Support for Generic Sensor Tutorial which provides instructions on how to add...
[apps/tidep0084.git] / tutorials / generic_sensor_tutorial / final / SensorToCloud / components / common / src / stream_socket_private.h
1 /******************************************************************************
2  @file stream_socket_private.h
4  @brief TIMAC 2.0 [private] contains internal(shared) functions between
5                   server & client socket abstraction layer.
7  Group: WCS LPC
8  $Target Devices: Linux: AM335x, Embedded Devices: CC1310, CC1350$
10  ******************************************************************************
11  $License: BSD3 2016 $
12   
13    Copyright (c) 2015, Texas Instruments Incorporated
14    All rights reserved.
15   
16    Redistribution and use in source and binary forms, with or without
17    modification, are permitted provided that the following conditions
18    are met:
19   
20    *  Redistributions of source code must retain the above copyright
21       notice, this list of conditions and the following disclaimer.
22   
23    *  Redistributions in binary form must reproduce the above copyright
24       notice, this list of conditions and the following disclaimer in the
25       documentation and/or other materials provided with the distribution.
26   
27    *  Neither the name of Texas Instruments Incorporated nor the names of
28       its contributors may be used to endorse or promote products derived
29       from this software without specific prior written permission.
30   
31    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34    PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
38    OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
41    EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  ******************************************************************************
43  $Release Name: TI-15.4Stack Linux x64 SDK$
44  $Release Date: Jun 28, 2017 (2.02.00.03)$
45  *****************************************************************************/
47 #if !defined(STEAM_SOCKET_PRIVATE_H)
48 #define STEAM_SOCKET_PRIVATE_H
50 #define _STREAM_IMPLIMENTOR_ 1
51 #include "stream_private.h"
53 #if _STREAM_SOCKET_PRIVATE != 1450384394
54 /* this is not a public header do not use */
55 #error "This file is private to the stream socket implementation"
56 #endif
58 /*!
59  * @struct linux_socket
60  * @brief  [private] struct common to client & server sockets
61  */
63 struct linux_socket {
64     /*! used to verify the the contents of this structure */
65     const int *test_ptr;
67     /*! Back pointer to the parent IO stream owning this structure */
68     struct io_stream *pParent;
70     /*! error prefix [compile time constant string] used for error messages */
71     const char *err_action;
73     /*! Socket configuration as supplied by the user */
74     struct socket_cfg cfg;
76     /*! File descriptor associated with this socket */
77     intptr_t  h;
79     /*! True if this socket is currently connected */
80     bool   is_connected;
82     /*! Connection id */
83     int    connection_id;
85     /*! For accepted server sockets, the address/port of the "other" socket.
86      *
87      * Per: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/socket.h.html
88      *
89      * The <sys/socket.h> header shall define the sockaddr_storage structure.
90      * This structure shall be: Large enough to accommodate all supported
91      * protocol-specific address structures; Aligned .. [etc...]
92      *
93      * thus this works for both inet4 and inet6 sockets
94      */
95     struct sockaddr_storage other;
96     /* for use with "other" above */
97     socklen_t       other_len;
98 };
100 /*!
101  * @brief Portable function for socket error num
102  * @param returns os-specific error number as an integer.
103  */
104 int _socket_errno(void);
106 /*! common socket initialization steps for a linux socket
107  * @param pCFG - the socket configuration
108  * @param pFUNC - callback functions to use in the socket.
109  * @returns pointer to a 'linux socket' structure.
110  */
111 struct linux_socket * _stream_socket_create(
112     const struct socket_cfg *pCFG,
113     const struct io_stream_funcs *pFuncs);
115 /*!
116  * @brief release resources for this socket.
117  */
118 void _stream_socket_destroy(struct linux_socket *pS);
120 /*!
121  * @brief Log an appropriate error message
122  * @param - the socket
123  * @param - primary error message
124  * @param - err number from system
125  * @param - err msg specific to the error number.
126  */
127 void _stream_socket_error(struct linux_socket *pS,
128                            const char *msg1,
129                            int errnum,
130                            const char *msg2);
132 /*!
133  * @brief convert opaque handle into a socket pointer
134  * @param h - the opaque handle
135  * @param code - the expected socket type
136  * @returns NULL on error or if socket is not of correct type
137  */
138 struct linux_socket *_stream_socket_h2ps(intptr_t h, int code);
140 /*!
141  * @brief Convert io stream, of expected type 'code' to a linux socket pointer
142  * @param pIO - the io stream
143  * @param code - the expected type of socket
144  * @returns NULL if the socket is not of the correct type, otherwise pointer
145  */
146 struct linux_socket *_stream_socket_io2ps(struct io_stream *pIO, int code);
148 /*!
149  * @brief Perform the common socket close operations for all socket types
150  * @param pS - the socket to close
151  */
152 void _stream_socket_close(struct linux_socket *pS);
154 /*!
155  * @brief Poll a socket for readablity
156  * @param pS - the socket
157  * @param mSecs_timeout - how long to wait
158  * @returns true if readable
159  */
160 bool _stream_socket_poll(struct linux_socket *pS, int mSecs_timeout);
162 /*!
163  * @brief bind this socket (server/client) to a specific interface.
164  * @param pS - the socket information
165  * @return 0 on sucess
166  */
167 int _stream_socket_bind_to_device(struct linux_socket *pS);
169 /*!
170  * @brief Mark socket as reusable
171  * @param pS - the socket
172  * @return 0 on sucess
173  */
174 int _stream_socket_reuse(struct linux_socket *pS);
176 #endif
178 /*
179  *  ========================================
180  *  Texas Instruments Micro Controller Style
181  *  ========================================
182  *  Local Variables:
183  *  mode: c
184  *  c-file-style: "bsd"
185  *  tab-width: 4
186  *  c-basic-offset: 4
187  *  indent-tabs-mode: nil
188  *  End:
189  *  vim:set  filetype=c tabstop=4 shiftwidth=4 expandtab=true
190  */