Commit bc7a44c6 authored by Sandrine Avakian's avatar Sandrine Avakian

Renaming functions into bctbx_<function_name>

Removing bctbx_bind, bctbx_connect and nctbx_socket_close from port.h/ port.c
Adding error support .
parent adcf0a8e
......@@ -351,7 +351,7 @@ void bctbx_set_memory_functions(BctoolboxMemoryFunctions *functions);
#define bctbx_new(type,count) (type*)bctbx_malloc(sizeof(type)*(count))
#define bctbx_new0(type,count) (type*)bctbx_malloc0(sizeof(type)*(count))
BCTBX_PUBLIC int bctbx_socket_close(bctbx_socket_t sock);
// BCTBX_PUBLIC int bctbx_socket_close(bctbx_socket_t sock);
BCTBX_PUBLIC int bctbx_socket_set_non_blocking(bctbx_socket_t sock);
BCTBX_PUBLIC char *bctbx_strndup(const char *str,int n);
......@@ -416,8 +416,8 @@ BCTBX_PUBLIC uint32_t bctbx_time_string_to_sec(const char *timeString);
BCTBX_PUBLIC unsigned int bctbx_random(void);
BCTBX_PUBLIC int bctbx_bind(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len);
BCTBX_PUBLIC int bctbx_connect(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len);
// BCTBX_PUBLIC int bctbx_bind(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len);
// BCTBX_PUBLIC int bctbx_connect(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len);
BCTBX_PUBLIC ssize_t bctbx_send(bctbx_socket_t socket, const void *buffer, size_t length, int flags);
BCTBX_PUBLIC ssize_t bctbx_sendto(bctbx_socket_t socket, const void *message, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len);
BCTBX_PUBLIC ssize_t bctbx_recv(bctbx_socket_t socket, void *buffer, size_t length, int flags);
......
/*
vconnect.h
Copyright (C) 2016 Belledonne Communications SARL
Copyright (C) 2017 Belledonne Communications SARL
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
......@@ -38,11 +38,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <unistd.h>
#endif
#if !defined(_WIN32) && !defined(_WIN32_WCE)
#define getSocketError() strerror(errno)
#else
#define getSocketError() __bctbx_getWinSocketError(WSAGetLastError())
#endif
#define BCTBX_VCONNECT_OK 0 /* Successful result */
#define BCTBX_VCONNECT_ERROR -255 /* Some kind of disk I/O error occurred */
#define BCTBX_VCONNECT_ERROR -255 /* Some kind of socket error occurred */
#ifdef __cplusplus
......@@ -54,7 +58,9 @@ extern "C"{
* Methods associated with the bctbx_vsocket_api_t.
*/
typedef struct bctbx_vsocket_methods_t bctbx_vsocket_methods_t;
/**
*
*/
struct bctbx_vsocket_methods_t {
......@@ -68,7 +74,11 @@ struct bctbx_vsocket_methods_t {
int (*pFuncSetSockOpt)(bctbx_socket_t sockfd, int level, int optname,
const void *optval, socklen_t optlen);
int (*pFuncClose)(bctbx_socket_t sock);
char* (*pFuncGetError)(int err);
int (*pFuncShutdown)(bctbx_socket_t sock, int how);
};
......@@ -88,31 +98,83 @@ struct bctbx_vsocket_api_t {
*/
BCTBX_PUBLIC bctbx_vsocket_api_t *bc_create_vsocket_api(void);
/**
* [bctbx_socket description]
* @param socket_family [description]
* @param socket_type [description]
* @param protocol [description]
* @return [description]
*/
BCTBX_PUBLIC int bctbx_socket(int socket_family, int socket_type, int protocol);
BCTBX_PUBLIC int bctbx_vsocket(int socket_family, int socket_type, int protocol);
BCTBX_PUBLIC int bctbx_vgetsockname(bctbx_socket_t sockfd, struct sockaddr *addr, socklen_t *addrlen);
BCTBX_PUBLIC int bctbx_vgetsockopt(bctbx_socket_t sockfd, int level, int optname,
/**
* [bctbx_getsockname description]
* @param sockfd [description]
* @param addr [description]
* @param addrlen [description]
* @return [description]
*/
BCTBX_PUBLIC int bctbx_getsockname(bctbx_socket_t sockfd, struct sockaddr *addr, socklen_t *addrlen);
/**
* [bctbx_getsockopt description]
* @param sockfd [description]
* @param level [description]
* @param optname [description]
* @param optval [description]
* @param optlen [description]
* @return [description]
*/
BCTBX_PUBLIC int bctbx_getsockopt(bctbx_socket_t sockfd, int level, int optname,
void *optval, socklen_t *optlen);
BCTBX_PUBLIC int bctbx_vsetsockopt(bctbx_socket_t sockfd, int level, int optname,
/**
* [bctbx_setsockopt description]
* @param sockfd [description]
* @param level [description]
* @param optname [description]
* @param optval [description]
* @param optlen [description]
* @return [description]
*/
BCTBX_PUBLIC int bctbx_setsockopt(bctbx_socket_t sockfd, int level, int optname,
const void *optval, socklen_t optlen);
BCTBX_PUBLIC int bctbx_vshutdown(bctbx_socket_t sockfd, int how);
/* UNUSED : REPLACED BY FUNIONS FROM PORT.C
bctbx_socket_close, bctbx_bind, bctbx_connect */
BCTBX_PUBLIC int bctbx_vclose(bctbx_socket_t sockfd);
BCTBX_PUBLIC int bctbx_vbind(bctbx_socket_t sockfd, const struct sockaddr *address, socklen_t address_len);
BCTBX_PUBLIC int bctbx_vconnect(bctbx_socket_t sockfd, const struct sockaddr *address, socklen_t address_len);
/**
* [bctbx_shutdown description]
* @param sockfd [description]
* @param how [description]
* @return [description]
*/
BCTBX_PUBLIC int bctbx_shutdown(bctbx_socket_t sockfd, int how);
/**
* [bctbx_socket_close description]
* @param sockfd [description]
* @return [description]
*/
BCTBX_PUBLIC int bctbx_socket_close(bctbx_socket_t sockfd);
/**
* [bctbx_bind description]
* @param sockfd [description]
* @param address [description]
* @param address_len [description]
* @return [description]
*/
BCTBX_PUBLIC int bctbx_bind(bctbx_socket_t sockfd, const struct sockaddr *address, socklen_t address_len);
/**
* [bctbx_connect description]
* @param sockfd [description]
* @param address [description]
* @param address_len [description]
* @return [description]
*/
BCTBX_PUBLIC int bctbx_connect(bctbx_socket_t sockfd, const struct sockaddr *address, socklen_t address_len);
/**
* Set default vsocket pointer pDefault to my_vsocket_api.
* By default, the global pointer is set to use vsocket implemnted in vfs.c
* By default, the global pointer is set to use vsocket implemented in vconnect.c
* @param my_vsocket_api Pointer to a bctbx_vsocket_api_t structure.
*/
BCTBX_PUBLIC void bctbx_vsocket_api_set_default(bctbx_vsocket_api_t *my_vsocket_api);
......@@ -120,14 +182,14 @@ BCTBX_PUBLIC void bctbx_vsocket_api_set_default(bctbx_vsocket_api_t *my_vsocket_
/**
* Returns the value of the global variable pDefault,
* pointing to the default vfs used.
* pointing to the default bctbx_vsocket_api_t used.
* @return Pointer to bctbx_vsocket_api_t set to operate as default vsocket.
*/
BCTBX_PUBLIC bctbx_vsocket_api_t* bctbx_vsocket_api_get_default(void);
/**
* Return pointer to standard vsocket impletentation.
* @return pointer to bcVfs
* @return pointer to bcSocketAPI
*/
BCTBX_PUBLIC bctbx_vsocket_api_t* bctbx_vsocket_api_get_standard(void);
......
......@@ -22,6 +22,7 @@
#include "bctoolbox/logging.h"
#include "bctoolbox/port.h"
#include "bctoolbox/vconnect.h"
#include "bctoolbox/list.h"
#include "utils.h"
......@@ -124,13 +125,13 @@ int bctbx_socket_set_non_blocking(bctbx_socket_t sock){
* closesocket on Win32.
* int retrun the result of the system method
*/
int bctbx_socket_close(bctbx_socket_t sock){
#if !defined(_WIN32) && !defined(_WIN32_WCE)
return close (sock);
#else
return closesocket(sock);
#endif
}
// int bctbx_socket_close(bctbx_socket_t sock){
// #if !defined(_WIN32) && !defined(_WIN32_WCE)
// return close (sock);
// #else
// return closesocket(sock);
// #endif
// }
int bctbx_file_exist(const char *pathname) {
return access(pathname,F_OK);
......@@ -997,13 +998,13 @@ bool_t bctbx_is_multicast_addr(const struct sockaddr *addr) {
#ifdef _WIN32
int bctbx_bind(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len) {
return bind(socket, address, (int)address_len);
}
// int bctbx_bind(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len) {
// return bind(socket, address, (int)address_len);
// }
int bctbx_connect(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len) {
return connect(socket, address, (int)address_len);
}
// int bctbx_connect(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len) {
// return connect(socket, address, (int)address_len);
// }
ssize_t bctbx_send(bctbx_socket_t socket, const void *buffer, size_t length, int flags) {
return send(socket, (const char *)buffer, (int)length, flags);
......@@ -1031,13 +1032,13 @@ ssize_t bctbx_write(int fd, const void *buf, size_t nbytes) {
#else
int bctbx_bind(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len) {
return bind(socket, address, address_len);
}
// int bctbx_bind(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len) {
// return bind(socket, address, address_len);
// }
int bctbx_connect(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len) {
return connect(socket, address, address_len);
}
// int bctbx_connect(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len) {
// return connect(socket, address, address_len);
// }
ssize_t bctbx_send(bctbx_socket_t socket, const void *buffer, size_t length, int flags) {
return send(socket, buffer, length, flags);
......
/*
vconnect.c
Copyright (C) 2016 Belledonne Communications SARL
Copyright (C) 2017 Belledonne Communications SARL
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
......@@ -16,6 +16,8 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
......@@ -29,6 +31,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <errno.h>
/**
* [_bind description]
* @param sock [description]
* @param address [description]
* @param address_len [description]
* @return [description]
*/
static int _bind (bctbx_socket_t sock, const struct sockaddr *address, socklen_t address_len){
#ifdef _WIN32
return bind(sock, address, (int)address_len);
......@@ -37,6 +47,7 @@ static int _bind (bctbx_socket_t sock, const struct sockaddr *address, socklen_t
#endif
}
static const bctbx_vsocket_methods_t bcSocketAPI = {
socket,
connect, /* from bctoolbox/port.c */
......@@ -46,15 +57,17 @@ static const bctbx_vsocket_methods_t bcSocketAPI = {
setsockopt,
#if !defined(_WIN32) && !defined(_WIN32_WCE) /* from bctoolbox/port.c */
close,
strerror,
#else
closesocket,
__bctbx_getWinSocketError,
#endif
shutdown,
};
static bctbx_vsocket_api_t bcvSocket = {
"bctbx_vsocket", /* vSockName */
"bctbx_socket", /* vSockName */
&bcSocketAPI, /*pSocketMethods */
};
......@@ -64,48 +77,51 @@ static bctbx_vsocket_api_t bcvSocket = {
static bctbx_vsocket_api_t *pDefaultvSocket = &bcvSocket;
int bctbx_vsocket(int socket_family, int socket_type, int protocol){
int bctbx_socket(int socket_family, int socket_type, int protocol){
return pDefaultvSocket->pSocketMethods->pFuncSocket( socket_family, socket_type, protocol);
}
int bctbx_vclose(bctbx_socket_t sock){
int bctbx_socket_close(bctbx_socket_t sock){
return pDefaultvSocket->pSocketMethods->pFuncClose(sock);
}
int bctbx_vbind(bctbx_socket_t sock, const struct sockaddr *address, socklen_t address_len){
int bctbx_bind(bctbx_socket_t sock, const struct sockaddr *address, socklen_t address_len){
return pDefaultvSocket->pSocketMethods->pFuncBind(sock, address, address_len);
}
int bctbx_vconnect(bctbx_socket_t sock, const struct sockaddr *address, socklen_t address_len){
int bctbx_connect(bctbx_socket_t sock, const struct sockaddr *address, socklen_t address_len){
return pDefaultvSocket->pSocketMethods->pFuncConnect(sock, address, address_len);
}
int bctbx_vgetsockname(bctbx_socket_t sockfd, struct sockaddr *addr, socklen_t *addrlen){
int bctbx_getsockname(bctbx_socket_t sockfd, struct sockaddr *addr, socklen_t *addrlen){
return pDefaultvSocket->pSocketMethods->pFuncGetSockName(sockfd, addr, addrlen);
}
int bctbx_vgetsockopt(bctbx_socket_t sockfd, int level, int optname,
int bctbx_getsockopt(bctbx_socket_t sockfd, int level, int optname,
void *optval, socklen_t* optlen){
return pDefaultvSocket->pSocketMethods->pFuncGetSockOpt(sockfd, level, optname, optval, optlen);
}
int bctbx_vsetsockopt(bctbx_socket_t sockfd, int level, int optname,
int bctbx_setsockopt(bctbx_socket_t sockfd, int level, int optname,
const void *optval, socklen_t optlen){
return pDefaultvSocket->pSocketMethods->pFuncSetSockOpt(sockfd, level, optname, optval, optlen);
}
int bctbx_vshutdown(bctbx_socket_t sock, int how){
int bctbx_shutdown(bctbx_socket_t sock, int how){
return pDefaultvSocket->pSocketMethods->pFuncShutdown(sock, how);
}
char* bctbx_socket_error(int errno){
return pDefaultvSocket->pSocketMethods->pFuncGetError(errno);
}
void bctbx_vsocket_api_set_default(bctbx_vsocket_api_t *my_vsocket_api) {
......@@ -123,5 +139,5 @@ bctbx_vsocket_api_t* bctbx_vsocket_api_get_standard(void) {
return &bcvSocket;
}
/* Pointer to default VFS initialized to standard VFS implemented here.*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment