Changes in uspace/lib/c/generic/net/socket_client.c [b4c9c61:1bfd3d3] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/net/socket_client.c
rb4c9c61 r1bfd3d3 79 79 typedef struct socket socket_t; 80 80 81 /** Type definition of the socket specific data pointer.82 * @see socket83 */84 typedef socket_t *socket_ref;85 86 81 /** Socket specific data. 87 82 * … … 162 157 163 158 /** Active sockets. */ 164 sockets_ refsockets;159 sockets_t *sockets; 165 160 166 161 /** Safety lock. … … 183 178 /** Returns the active sockets. 184 179 * 185 * @return sThe active sockets.186 */ 187 static sockets_ refsocket_get_sockets(void)180 * @return The active sockets. 181 */ 182 static sockets_t *socket_get_sockets(void) 188 183 { 189 184 if (!socket_globals.sockets) { 190 185 socket_globals.sockets = 191 (sockets_ ref) malloc(sizeof(sockets_t));186 (sockets_t *) malloc(sizeof(sockets_t)); 192 187 if (!socket_globals.sockets) 193 188 return NULL; … … 213 208 ipc_callid_t callid; 214 209 ipc_call_t call; 215 socket_ refsocket;210 socket_t *socket; 216 211 int rc; 217 212 … … 291 286 * Connects to the TCP module if necessary. 292 287 * 293 * @return sThe TCP module phone.294 * @return sOther error codes as defined for the288 * @return The TCP module phone. 289 * @return Other error codes as defined for the 295 290 * bind_service_timeout() function. 296 291 */ … … 310 305 * Connects to the UDP module if necessary. 311 306 * 312 * @return sThe UDP module phone.313 * @return sOther error codes as defined for the307 * @return The UDP module phone. 308 * @return Other error codes as defined for the 314 309 * bind_service_timeout() function. 315 310 */ … … 327 322 /** Tries to find a new free socket identifier. 328 323 * 329 * @return sThe new socket identifier.330 * @return sELIMIT if there is no socket identifier available.324 * @return The new socket identifier. 325 * @return ELIMIT if there is no socket identifier available. 331 326 */ 332 327 static int socket_generate_new_id(void) 333 328 { 334 sockets_ refsockets;329 sockets_t *sockets; 335 330 int socket_id = 0; 336 331 int count; … … 372 367 */ 373 368 static void 374 socket_initialize(socket_ refsocket, int socket_id, int phone,369 socket_initialize(socket_t *socket, int socket_id, int phone, 375 370 services_t service) 376 371 { … … 392 387 * @param[in] type Socket type. 393 388 * @param[in] protocol Socket protocol. 394 * @return sThe socket identifier on success.395 * @return sEPFNOTSUPPORT if the protocol family is not supported.396 * @return sESOCKNOTSUPPORT if the socket type is not supported.397 * @return sEPROTONOSUPPORT if the protocol is not supported.398 * @return sENOMEM if there is not enough memory left.399 * @return sELIMIT if there was not a free socket identifier found389 * @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 400 395 * this time. 401 * @return sOther error codes as defined for the NET_SOCKET message.402 * @return sOther error codes as defined for the396 * @return Other error codes as defined for the NET_SOCKET message. 397 * @return Other error codes as defined for the 403 398 * bind_service_timeout() function. 404 399 */ 405 400 int socket(int domain, int type, int protocol) 406 401 { 407 socket_ refsocket;402 socket_t *socket; 408 403 int phone; 409 404 int socket_id; … … 463 458 464 459 // create a new socket structure 465 socket = (socket_ ref) malloc(sizeof(socket_t));460 socket = (socket_t *) malloc(sizeof(socket_t)); 466 461 if (!socket) 467 462 return ENOMEM; … … 514 509 * @param[in] data The data to be sent. 515 510 * @param[in] datalength The data length. 516 * @return sEOK on success.517 * @return sENOTSOCK if the socket is not found.518 * @return sEBADMEM if the data parameter is NULL.519 * @return sNO_DATA if the datalength parameter is zero (0).520 * @return sOther error codes as defined for the spcific message.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. 521 516 */ 522 517 static int … … 524 519 const void *data, size_t datalength) 525 520 { 526 socket_ refsocket;521 socket_t *socket; 527 522 aid_t message_id; 528 523 ipcarg_t result; … … 559 554 * @param[in] my_addr The port address. 560 555 * @param[in] addrlen The address length. 561 * @return sEOK on success.562 * @return sENOTSOCK if the socket is not found.563 * @return sEBADMEM if the my_addr parameter is NULL.564 * @return sNO_DATA if the addlen parameter is zero.565 * @return sOther error codes as defined for the NET_SOCKET_BIND556 * @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 566 561 * message. 567 562 */ … … 580 575 * @param[in] socket_id Socket identifier. 581 576 * @param[in] backlog The maximum number of waiting sockets to be accepted. 582 * @return sEOK on success.583 * @return sEINVAL if the backlog parameter is not positive (<=0).584 * @return sENOTSOCK if the socket is not found.585 * @return sOther error codes as defined for the NET_SOCKET_LISTEN577 * @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 586 581 * message. 587 582 */ 588 583 int listen(int socket_id, int backlog) 589 584 { 590 socket_ refsocket;585 socket_t *socket; 591 586 int result; 592 587 … … 618 613 * @param[out] cliaddr The remote client address. 619 614 * @param[in] addrlen The address length. 620 * @return sEOK on success.621 * @return sEBADMEM if the cliaddr or addrlen parameter is NULL.622 * @return sEINVAL if the backlog parameter is not positive (<=0).623 * @return sENOTSOCK if the socket is not found.624 * @return sOther error codes as defined for the NET_SOCKET_ACCEPT615 * @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 625 620 * message. 626 621 */ 627 622 int accept(int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen) 628 623 { 629 socket_ refsocket;630 socket_ refnew_socket;624 socket_t *socket; 625 socket_t *new_socket; 631 626 aid_t message_id; 632 627 ipcarg_t ipc_result; … … 661 656 662 657 // create a new scoket 663 new_socket = (socket_ ref) malloc(sizeof(socket_t));658 new_socket = (socket_t *) malloc(sizeof(socket_t)); 664 659 if (!new_socket) { 665 660 fibril_mutex_unlock(&socket->accept_lock); … … 721 716 * @param[in] serv_addr The remote server address. 722 717 * @param[in] addrlen The address length. 723 * @return sEOK on success.724 * @return sEBADMEM if the serv_addr parameter is NULL.725 * @return sNO_DATA if the addlen parameter is zero.726 * @return sENOTSOCK if the socket is not found.727 * @return sOther error codes as defined for the NET_SOCKET_CONNECT718 * @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 728 723 * message. 729 724 */ … … 745 740 * @param[in] socket The socket to be destroyed. 746 741 */ 747 static void socket_destroy(socket_ refsocket)742 static void socket_destroy(socket_t *socket) 748 743 { 749 744 int accepted_id; … … 761 756 * 762 757 * @param[in] socket_id Socket identifier. 763 * @return sEOK on success.764 * @return sENOTSOCK if the socket is not found.765 * @return sEINPROGRESS if there is another blocking function in758 * @return EOK on success. 759 * @return ENOTSOCK if the socket is not found. 760 * @return EINPROGRESS if there is another blocking function in 766 761 * progress. 767 * @return sOther error codes as defined for the NET_SOCKET_CLOSE762 * @return Other error codes as defined for the NET_SOCKET_CLOSE 768 763 * message. 769 764 */ 770 765 int closesocket(int socket_id) 771 766 { 772 socket_ refsocket;767 socket_t *socket; 773 768 int rc; 774 769 … … 811 806 * sockets. 812 807 * @param[in] addrlen The address length. Used only if toaddr is not NULL. 813 * @return sEOK on success.814 * @return sENOTSOCK if the socket is not found.815 * @return sEBADMEM if the data or toaddr parameter is NULL.816 * @return sNO_DATA if the datalength or the addrlen parameter is808 * @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 817 812 * zero (0). 818 * @return sOther error codes as defined for the NET_SOCKET_SENDTO813 * @return Other error codes as defined for the NET_SOCKET_SENDTO 819 814 * message. 820 815 */ … … 824 819 socklen_t addrlen) 825 820 { 826 socket_ refsocket;821 socket_t *socket; 827 822 aid_t message_id; 828 823 ipcarg_t result; … … 913 908 * @param[in] datalength The data length. 914 909 * @param[in] flags Various send flags. 915 * @return sEOK on success.916 * @return sENOTSOCK if the socket is not found.917 * @return sEBADMEM if the data parameter is NULL.918 * @return sNO_DATA if the datalength parameter is zero.919 * @return sOther error codes as defined for the NET_SOCKET_SEND910 * @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 920 915 * message. 921 916 */ … … 937 932 * @param[in] toaddr The destination address. 938 933 * @param[in] addrlen The address length. 939 * @return sEOK on success.940 * @return sENOTSOCK if the socket is not found.941 * @return sEBADMEM if the data or toaddr parameter is NULL.942 * @return sNO_DATA if the datalength or the addrlen parameter is934 * @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 943 938 * zero. 944 * @return sOther error codes as defined for the NET_SOCKET_SENDTO939 * @return Other error codes as defined for the NET_SOCKET_SENDTO 945 940 * message. 946 941 */ … … 971 966 * read. The actual address length is set. Used only if 972 967 * fromaddr is not NULL. 973 * @return sEOK on success.974 * @return sENOTSOCK if the socket is not found.975 * @return sEBADMEM if the data parameter is NULL.976 * @return sNO_DATA if the datalength or addrlen parameter is zero.977 * @return sOther error codes as defined for the spcific message.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. 978 973 */ 979 974 static int … … 981 976 int flags, struct sockaddr *fromaddr, socklen_t *addrlen) 982 977 { 983 socket_ refsocket;978 socket_t *socket; 984 979 aid_t message_id; 985 980 ipcarg_t ipc_result; … … 1100 1095 * @param[in] datalength The data length. 1101 1096 * @param[in] flags Various receive flags. 1102 * @return sEOK on success.1103 * @return sENOTSOCK if the socket is not found.1104 * @return sEBADMEM if the data parameter is NULL.1105 * @return sNO_DATA if the datalength parameter is zero.1106 * @return sOther error codes as defined for the NET_SOCKET_RECV1097 * @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 1107 1102 * message. 1108 1103 */ … … 1123 1118 * @param[in,out] addrlen The address length. The maximum address length is 1124 1119 * read. The actual address length is set. 1125 * @return sEOK on success.1126 * @return sENOTSOCK if the socket is not found.1127 * @return sEBADMEM if the data or fromaddr parameter is NULL.1128 * @return sNO_DATA if the datalength or addrlen parameter is zero.1129 * @return sOther error codes as defined for the NET_SOCKET_RECVFROM1120 * @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 1130 1125 * message. 1131 1126 */ … … 1153 1148 * @param[in,out] optlen The value buffer length. The maximum length is read. 1154 1149 * The actual length is set. 1155 * @return sEOK on success.1156 * @return sENOTSOCK if the socket is not found.1157 * @return sEBADMEM if the value or optlen parameter is NULL.1158 * @return sNO_DATA if the optlen parameter is zero.1159 * @return sOther error codes as defined for the1150 * @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 1160 1155 * NET_SOCKET_GETSOCKOPT message. 1161 1156 */ … … 1163 1158 getsockopt(int socket_id, int level, int optname, void *value, size_t *optlen) 1164 1159 { 1165 socket_ refsocket;1160 socket_t *socket; 1166 1161 aid_t message_id; 1167 1162 ipcarg_t result; … … 1206 1201 * @param[in] value The value to be set. 1207 1202 * @param[in] optlen The value length. 1208 * @return sEOK on success.1209 * @return sENOTSOCK if the socket is not found.1210 * @return sEBADMEM if the value parameter is NULL.1211 * @return sNO_DATA if the optlen parameter is zero.1212 * @return sOther error codes as defined for the1203 * @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 1213 1208 * NET_SOCKET_SETSOCKOPT message. 1214 1209 */
Note:
See TracChangeset
for help on using the changeset viewer.