Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/net/socket_client.c

    r1bfd3d3 rb4c9c61  
    7979typedef struct socket socket_t;
    8080
     81/** Type definition of the socket specific data pointer.
     82 * @see socket
     83 */
     84typedef socket_t *socket_ref;
     85
    8186/** Socket specific data.
    8287 *
     
    157162
    158163        /** Active sockets. */
    159         sockets_t *sockets;
     164        sockets_ref sockets;
    160165
    161166        /** Safety lock.
     
    178183/** Returns the active sockets.
    179184 *
    180  *  @return             The active sockets.
    181  */
    182 static sockets_t *socket_get_sockets(void)
     185 *  @returns            The active sockets.
     186 */
     187static sockets_ref socket_get_sockets(void)
    183188{
    184189        if (!socket_globals.sockets) {
    185190                socket_globals.sockets =
    186                     (sockets_t *) malloc(sizeof(sockets_t));
     191                    (sockets_ref) malloc(sizeof(sockets_t));
    187192                if (!socket_globals.sockets)
    188193                        return NULL;
     
    208213        ipc_callid_t callid;
    209214        ipc_call_t call;
    210         socket_t *socket;
     215        socket_ref socket;
    211216        int rc;
    212217
     
    286291 * Connects to the TCP module if necessary.
    287292 *
    288  * @return              The TCP module phone.
    289  * @return              Other error codes as defined for the
     293 * @returns             The TCP module phone.
     294 * @returns             Other error codes as defined for the
    290295 *                      bind_service_timeout() function.
    291296 */
     
    305310 * Connects to the UDP module if necessary.
    306311 *
    307  * @return              The UDP module phone.
    308  * @return              Other error codes as defined for the
     312 * @returns             The UDP module phone.
     313 * @returns             Other error codes as defined for the
    309314 *                      bind_service_timeout() function.
    310315 */
     
    322327/** Tries to find a new free socket identifier.
    323328 *
    324  * @return              The new socket identifier.
    325  * @return              ELIMIT if there is no socket identifier available.
     329 * @returns             The new socket identifier.
     330 * @returns             ELIMIT if there is no socket identifier available.
    326331 */
    327332static int socket_generate_new_id(void)
    328333{
    329         sockets_t *sockets;
     334        sockets_ref sockets;
    330335        int socket_id = 0;
    331336        int count;
     
    367372 */
    368373static void
    369 socket_initialize(socket_t *socket, int socket_id, int phone,
     374socket_initialize(socket_ref socket, int socket_id, int phone,
    370375    services_t service)
    371376{
     
    387392 * @param[in] type      Socket type.
    388393 * @param[in] protocol  Socket protocol.
    389  * @return              The socket identifier on success.
    390  * @return              EPFNOTSUPPORT if the protocol family is not supported.
    391  * @return              ESOCKNOTSUPPORT if the socket type is not supported.
    392  * @return              EPROTONOSUPPORT if the protocol is not supported.
    393  * @return              ENOMEM if there is not enough memory left.
    394  * @return              ELIMIT if there was not a free socket identifier found
     394 * @returns             The socket identifier on success.
     395 * @returns             EPFNOTSUPPORT if the protocol family is not supported.
     396 * @returns             ESOCKNOTSUPPORT if the socket type is not supported.
     397 * @returns             EPROTONOSUPPORT if the protocol is not supported.
     398 * @returns             ENOMEM if there is not enough memory left.
     399 * @returns             ELIMIT if there was not a free socket identifier found
    395400 *                      this time.
    396  * @return              Other error codes as defined for the NET_SOCKET message.
    397  * @return              Other error codes as defined for the
     401 * @returns             Other error codes as defined for the NET_SOCKET message.
     402 * @returns             Other error codes as defined for the
    398403 *                      bind_service_timeout() function.
    399404 */
    400405int socket(int domain, int type, int protocol)
    401406{
    402         socket_t *socket;
     407        socket_ref socket;
    403408        int phone;
    404409        int socket_id;
     
    458463
    459464        // create a new socket structure
    460         socket = (socket_t *) malloc(sizeof(socket_t));
     465        socket = (socket_ref) malloc(sizeof(socket_t));
    461466        if (!socket)
    462467                return ENOMEM;
     
    509514 * @param[in] data      The data to be sent.
    510515 * @param[in] datalength The data length.
    511  * @return              EOK on success.
    512  * @return              ENOTSOCK if the socket is not found.
    513  * @return              EBADMEM if the data parameter is NULL.
    514  * @return              NO_DATA if the datalength parameter is zero (0).
    515  * @return              Other error codes as defined for the spcific message.
     516 * @returns             EOK on success.
     517 * @returns             ENOTSOCK if the socket is not found.
     518 * @returns             EBADMEM if the data parameter is NULL.
     519 * @returns             NO_DATA if the datalength parameter is zero (0).
     520 * @returns             Other error codes as defined for the spcific message.
    516521 */
    517522static int
     
    519524    const void *data, size_t datalength)
    520525{
    521         socket_t *socket;
     526        socket_ref socket;
    522527        aid_t message_id;
    523528        ipcarg_t result;
     
    554559 * @param[in] my_addr   The port address.
    555560 * @param[in] addrlen   The address length.
    556  * @return              EOK on success.
    557  * @return              ENOTSOCK if the socket is not found.
    558  * @return              EBADMEM if the my_addr parameter is NULL.
    559  * @return              NO_DATA if the addlen parameter is zero.
    560  * @return              Other error codes as defined for the NET_SOCKET_BIND
     561 * @returns             EOK on success.
     562 * @returns             ENOTSOCK if the socket is not found.
     563 * @returns             EBADMEM if the my_addr parameter is NULL.
     564 * @returns             NO_DATA if the addlen parameter is zero.
     565 * @returns             Other error codes as defined for the NET_SOCKET_BIND
    561566 *                      message.
    562567 */
     
    575580 * @param[in] socket_id Socket identifier.
    576581 * @param[in] backlog   The maximum number of waiting sockets to be accepted.
    577  * @return              EOK on success.
    578  * @return              EINVAL if the backlog parameter is not positive (<=0).
    579  * @return              ENOTSOCK if the socket is not found.
    580  * @return              Other error codes as defined for the NET_SOCKET_LISTEN
     582 * @returns             EOK on success.
     583 * @returns             EINVAL if the backlog parameter is not positive (<=0).
     584 * @returns             ENOTSOCK if the socket is not found.
     585 * @returns             Other error codes as defined for the NET_SOCKET_LISTEN
    581586 *                      message.
    582587 */
    583588int listen(int socket_id, int backlog)
    584589{
    585         socket_t *socket;
     590        socket_ref socket;
    586591        int result;
    587592
     
    613618 * @param[out] cliaddr  The remote client address.
    614619 * @param[in] addrlen   The address length.
    615  * @return              EOK on success.
    616  * @return              EBADMEM if the cliaddr or addrlen parameter is NULL.
    617  * @return              EINVAL if the backlog parameter is not positive (<=0).
    618  * @return              ENOTSOCK if the socket is not found.
    619  * @return              Other error codes as defined for the NET_SOCKET_ACCEPT
     620 * @returns             EOK on success.
     621 * @returns             EBADMEM if the cliaddr or addrlen parameter is NULL.
     622 * @returns             EINVAL if the backlog parameter is not positive (<=0).
     623 * @returns             ENOTSOCK if the socket is not found.
     624 * @returns             Other error codes as defined for the NET_SOCKET_ACCEPT
    620625 *                      message.
    621626 */
    622627int accept(int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen)
    623628{
    624         socket_t *socket;
    625         socket_t *new_socket;
     629        socket_ref socket;
     630        socket_ref new_socket;
    626631        aid_t message_id;
    627632        ipcarg_t ipc_result;
     
    656661
    657662        // create a new scoket
    658         new_socket = (socket_t *) malloc(sizeof(socket_t));
     663        new_socket = (socket_ref) malloc(sizeof(socket_t));
    659664        if (!new_socket) {
    660665                fibril_mutex_unlock(&socket->accept_lock);
     
    716721 * @param[in] serv_addr The remote server address.
    717722 * @param[in] addrlen   The address length.
    718  * @return              EOK on success.
    719  * @return              EBADMEM if the serv_addr parameter is NULL.
    720  * @return              NO_DATA if the addlen parameter is zero.
    721  * @return              ENOTSOCK if the socket is not found.
    722  * @return              Other error codes as defined for the NET_SOCKET_CONNECT
     723 * @returns             EOK on success.
     724 * @returns             EBADMEM if the serv_addr parameter is NULL.
     725 * @returns             NO_DATA if the addlen parameter is zero.
     726 * @returns             ENOTSOCK if the socket is not found.
     727 * @returns             Other error codes as defined for the NET_SOCKET_CONNECT
    723728 *                      message.
    724729 */
     
    740745 * @param[in] socket    The socket to be destroyed.
    741746 */
    742 static void socket_destroy(socket_t *socket)
     747static void socket_destroy(socket_ref socket)
    743748{
    744749        int accepted_id;
     
    756761 *
    757762 * @param[in] socket_id Socket identifier.
    758  * @return              EOK on success.
    759  * @return              ENOTSOCK if the socket is not found.
    760  * @return              EINPROGRESS if there is another blocking function in
     763 * @returns             EOK on success.
     764 * @returns             ENOTSOCK if the socket is not found.
     765 * @returns             EINPROGRESS if there is another blocking function in
    761766 *                      progress.
    762  * @return              Other error codes as defined for the NET_SOCKET_CLOSE
     767 * @returns             Other error codes as defined for the NET_SOCKET_CLOSE
    763768 *                      message.
    764769 */
    765770int closesocket(int socket_id)
    766771{
    767         socket_t *socket;
     772        socket_ref socket;
    768773        int rc;
    769774
     
    806811 *                      sockets.
    807812 * @param[in] addrlen   The address length. Used only if toaddr is not NULL.
    808  * @return              EOK on success.
    809  * @return              ENOTSOCK if the socket is not found.
    810  * @return              EBADMEM if the data or toaddr parameter is NULL.
    811  * @return              NO_DATA if the datalength or the addrlen parameter is
     813 * @returns             EOK on success.
     814 * @returns             ENOTSOCK if the socket is not found.
     815 * @returns             EBADMEM if the data or toaddr parameter is NULL.
     816 * @returns             NO_DATA if the datalength or the addrlen parameter is
    812817 *                      zero (0).
    813  * @return              Other error codes as defined for the NET_SOCKET_SENDTO
     818 * @returns             Other error codes as defined for the NET_SOCKET_SENDTO
    814819 *                      message.
    815820 */
     
    819824    socklen_t addrlen)
    820825{
    821         socket_t *socket;
     826        socket_ref socket;
    822827        aid_t message_id;
    823828        ipcarg_t result;
     
    908913 * @param[in] datalength The data length.
    909914 * @param[in] flags     Various send flags.
    910  * @return              EOK on success.
    911  * @return              ENOTSOCK if the socket is not found.
    912  * @return              EBADMEM if the data parameter is NULL.
    913  * @return              NO_DATA if the datalength parameter is zero.
    914  * @return              Other error codes as defined for the NET_SOCKET_SEND
     915 * @returns             EOK on success.
     916 * @returns             ENOTSOCK if the socket is not found.
     917 * @returns             EBADMEM if the data parameter is NULL.
     918 * @returns             NO_DATA if the datalength parameter is zero.
     919 * @returns             Other error codes as defined for the NET_SOCKET_SEND
    915920 *                      message.
    916921 */
     
    932937 * @param[in] toaddr    The destination address.
    933938 * @param[in] addrlen   The address length.
    934  * @return              EOK on success.
    935  * @return              ENOTSOCK if the socket is not found.
    936  * @return              EBADMEM if the data or toaddr parameter is NULL.
    937  * @return              NO_DATA if the datalength or the addrlen parameter is
     939 * @returns             EOK on success.
     940 * @returns             ENOTSOCK if the socket is not found.
     941 * @returns             EBADMEM if the data or toaddr parameter is NULL.
     942 * @returns             NO_DATA if the datalength or the addrlen parameter is
    938943 *                      zero.
    939  * @return              Other error codes as defined for the NET_SOCKET_SENDTO
     944 * @returns             Other error codes as defined for the NET_SOCKET_SENDTO
    940945 *                      message.
    941946 */
     
    966971 *                      read. The actual address length is set. Used only if
    967972 *                      fromaddr is not NULL.
    968  * @return              EOK on success.
    969  * @return              ENOTSOCK if the socket is not found.
    970  * @return              EBADMEM if the data parameter is NULL.
    971  * @return              NO_DATA if the datalength or addrlen parameter is zero.
    972  * @return              Other error codes as defined for the spcific message.
     973 * @returns             EOK on success.
     974 * @returns             ENOTSOCK if the socket is not found.
     975 * @returns             EBADMEM if the data parameter is NULL.
     976 * @returns             NO_DATA if the datalength or addrlen parameter is zero.
     977 * @returns             Other error codes as defined for the spcific message.
    973978 */
    974979static int
     
    976981    int flags, struct sockaddr *fromaddr, socklen_t *addrlen)
    977982{
    978         socket_t *socket;
     983        socket_ref socket;
    979984        aid_t message_id;
    980985        ipcarg_t ipc_result;
     
    10951100 * @param[in] datalength The data length.
    10961101 * @param[in] flags     Various receive flags.
    1097  * @return              EOK on success.
    1098  * @return              ENOTSOCK if the socket is not found.
    1099  * @return              EBADMEM if the data parameter is NULL.
    1100  * @return              NO_DATA if the datalength parameter is zero.
    1101  * @return              Other error codes as defined for the NET_SOCKET_RECV
     1102 * @returns             EOK on success.
     1103 * @returns             ENOTSOCK if the socket is not found.
     1104 * @returns             EBADMEM if the data parameter is NULL.
     1105 * @returns             NO_DATA if the datalength parameter is zero.
     1106 * @returns             Other error codes as defined for the NET_SOCKET_RECV
    11021107 *                      message.
    11031108 */
     
    11181123 * @param[in,out] addrlen The address length. The maximum address length is
    11191124 *                      read. The actual address length is set.
    1120  * @return              EOK on success.
    1121  * @return              ENOTSOCK if the socket is not found.
    1122  * @return              EBADMEM if the data or fromaddr parameter is NULL.
    1123  * @return              NO_DATA if the datalength or addrlen parameter is zero.
    1124  * @return              Other error codes as defined for the NET_SOCKET_RECVFROM
     1125 * @returns             EOK on success.
     1126 * @returns             ENOTSOCK if the socket is not found.
     1127 * @returns             EBADMEM if the data or fromaddr parameter is NULL.
     1128 * @returns             NO_DATA if the datalength or addrlen parameter is zero.
     1129 * @returns             Other error codes as defined for the NET_SOCKET_RECVFROM
    11251130 *                      message.
    11261131 */
     
    11481153 * @param[in,out] optlen The value buffer length. The maximum length is read.
    11491154 *                      The actual length is set.
    1150  * @return              EOK on success.
    1151  * @return              ENOTSOCK if the socket is not found.
    1152  * @return              EBADMEM if the value or optlen parameter is NULL.
    1153  * @return              NO_DATA if the optlen parameter is zero.
    1154  * @return              Other error codes as defined for the
     1155 * @returns             EOK on success.
     1156 * @returns             ENOTSOCK if the socket is not found.
     1157 * @returns             EBADMEM if the value or optlen parameter is NULL.
     1158 * @returns             NO_DATA if the optlen parameter is zero.
     1159 * @returns             Other error codes as defined for the
    11551160 *                      NET_SOCKET_GETSOCKOPT message.
    11561161 */
     
    11581163getsockopt(int socket_id, int level, int optname, void *value, size_t *optlen)
    11591164{
    1160         socket_t *socket;
     1165        socket_ref socket;
    11611166        aid_t message_id;
    11621167        ipcarg_t result;
     
    12011206 * @param[in] value     The value to be set.
    12021207 * @param[in] optlen    The value length.
    1203  * @return              EOK on success.
    1204  * @return              ENOTSOCK if the socket is not found.
    1205  * @return              EBADMEM if the value parameter is NULL.
    1206  * @return              NO_DATA if the optlen parameter is zero.
    1207  * @return              Other error codes as defined for the
     1208 * @returns             EOK on success.
     1209 * @returns             ENOTSOCK if the socket is not found.
     1210 * @returns             EBADMEM if the value parameter is NULL.
     1211 * @returns             NO_DATA if the optlen parameter is zero.
     1212 * @returns             Other error codes as defined for the
    12081213 *                      NET_SOCKET_SETSOCKOPT message.
    12091214 */
Note: See TracChangeset for help on using the changeset viewer.