Add documentation to bsd.h and sfdnsres.h, etc.

This commit is contained in:
TuxSH 2018-02-19 19:11:28 +01:00 committed by plutoo
parent 5242771903
commit d33b26016d
14 changed files with 46 additions and 39 deletions

View File

@ -1,6 +1,6 @@
// TuxSH: removed definitions under _KERNEL ifdef blocks, modify the prototype of some functions, some other cleanup, etc.
#ifndef __BSD_VISIBLE
#define __BSD_VISIBLE
#define __BSD_VISIBLE 1
#endif
// Stubbed some stuff

View File

@ -1,6 +1,6 @@
// TuxSH: define __BSD_VISIBLE, change a lot of symbols, etc
#ifndef __BSD_VISIBLE
#define __BSD_VISIBLE
#define __BSD_VISIBLE 1
#endif
/*-

View File

@ -1,6 +1,6 @@
// TuxSH: removed definitions under _KERNEL ifdef blocks, modify the prototype of some functions, some other cleanup, etc.
#ifndef __BSD_VISIBLE
#define __BSD_VISIBLE
#define __BSD_VISIBLE 1
#endif
/*-

View File

@ -1,6 +1,6 @@
// TuxSH: removed definitions under _KERNEL ifdef blocks, modify the prototype of some functions, some other cleanup, etc.
#ifndef __BSD_VISIBLE
#define __BSD_VISIBLE
#define __BSD_VISIBLE 1
#endif
/*-

View File

@ -1,6 +1,6 @@
// TuxSH: removed definitions under _KERNEL ifdef blocks, modify the prototype of some functions, some other cleanup, etc.
#ifndef __BSD_VISIBLE
#define __BSD_VISIBLE
#define __BSD_VISIBLE 1
#endif
/*-

View File

@ -1,6 +1,6 @@
// TuxSH: removed definitions under _KERNEL ifdef blocks, modify the prototype of some functions, some other cleanup, etc.
#ifndef __BSD_VISIBLE
#define __BSD_VISIBLE
#define __BSD_VISIBLE 1
#endif
/*-

View File

@ -29,12 +29,11 @@ Result socketInitialize(const SocketInitConfig *config);
Result socketGetLastBsdResult(void);
/// Fetch the last sfdnsres Switch result code (thread-local).
Result socketGetLastSfdnsresResult(void);
/// Deinitializes the socket driver.
/// Deinitialize the socket driver.
void socketExit(void);
/// Initalize the socket driver using the default configuration.
static inline Result socketInitializeDefault(void)
{
static inline Result socketInitializeDefault(void) {
return socketInitialize(socketGetDefaultInitConfig());
}

View File

@ -1,18 +1,18 @@
/**
* @file bsd.h
* @brief BSD sockets (bsd:u/s) service IPC wrapper.
* @brief BSD sockets (bsd:u/s) service IPC wrapper. Please use socket.c instead.
* @author plutoo
* @author TuxSH
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../kernel/tmem.h"
#include <sys/socket.h> // for socklen_t
#include <sys/select.h> // for fd_set
#include <poll.h> // for struct pollfd, ndfs_t
#include "../types.h"
#include "../kernel/tmem.h"
/// Configuration structure for bsdInitalize
typedef struct {
u32 version; ///< Observed 1 on 2.0 LibAppletWeb, 2 on 3.0.
@ -31,11 +31,15 @@ typedef struct {
extern __thread Result g_bsdResult; ///< Last Switch "result", per-thread
extern __thread int g_bsdErrno; ///< Last errno, per-thread
const BsdInitConfig *bsdGetDefaultConfig(void);
/// Fetch the default configuration for bsdInitialize.
const BsdInitConfig *bsdGetDefaultInitConfig(void);
/// Initialize the BSD service.
Result bsdInitialize(const BsdInitConfig *config);
/// Deinitialize the BSD service.
void bsdExit(void);
int bsdSocket(int domain, int type, int protocol);
/// Like @ref bsdSocket but the newly created socket is immediately shut down.
int bsdSocketExempt(int domain, int type, int protocol);
int bsdOpen(const char *pathname, int flags);
int bsdSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
@ -52,8 +56,9 @@ int bsdGetPeerName(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
int bsdGetSockName(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
int bsdGetSockOpt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
int bsdListen(int sockfd, int backlog);
// The following two functions are supposed to be variadic
/// Made non-variadic for convenience.
int bsdIoctl(int fd, int request, void *data);
/// Made non-variadic for convenience.
int bsdFcntl(int fd, int cmd, int flags);
int bsdSetSockOpt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
int bsdShutdown(int sockfd, int how);
@ -61,11 +66,12 @@ int bsdShutdownAllSockets(int how);
ssize_t bsdWrite(int fd, const void *buf, size_t count);
ssize_t bsdRead(int fd, void *buf, size_t count);
int bsdClose(int fd);
/// Duplicate a socket (bsd:s).
int bsdDuplicateSocket(int sockfd);
//TODO: Reverse-engineer GetResourceStatistics, sendmmsg/recvmmsg (custom (un)serialization)
// TODO: Reverse-engineer GetResourceStatistics. Implement sendmmsg/recvmmsg (custom (un)serialization)
static inline Result bsdInitializeDefault(void)
{
return bsdInitialize(bsdGetDefaultConfig());
/// Initialize the BSD service using the default configuration.
static inline Result bsdInitializeDefault(void) {
return bsdInitialize(bsdGetDefaultInitConfig());
}

View File

@ -1,3 +1,9 @@
/**
* @file sfdnsres.h
* @brief Domain name resolution service IPC wrapper. Please use socket.c instead.
* @author TuxSH
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
@ -32,9 +38,11 @@ Result sfdnsresGetNameInfo(SfdnsresRequestResults *ret, const SfdnsresConfig *co
const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen,
char *serv, size_t servlen, int flags);
/// Requests an handle for use with @ref sfdnsresCancelSocketCall.
Result sfdnsresRequestCancelHandle(u32 *out_handle);
/// Bug: always sets errno ?
/// Cancels a DNS request (how? which requests?). Bug: always sets errno?
Result sfdnsresCancelSocketCall(SfdnsresRequestResults *ret, u32 handle);
/// Bug: always sets errno ?
/// Cancels all DNS requests made by the current process (how? which requests?). Bug: always sets errno?
Result sfdnsresCancelAllSocketCalls(SfdnsresRequestResults *ret);
/// Clears up to 4 DNS server IPs registered by bsdcfg (DHCP client, etc.).
Result sfdnsresClearDnsIpServerAddressArray(void);

View File

@ -1,6 +1,6 @@
// TuxSH: removed definitions under _KERNEL ifdef blocks, modify the prototype of some functions, some other cleanup, etc.
#ifndef __BSD_VISIBLE
#define __BSD_VISIBLE
#define __BSD_VISIBLE 1
#endif
/*-

View File

@ -1,7 +1,7 @@
// TuxSH: removed definitions under _KERNEL ifdef blocks, modify the prototype of some functions, some other cleanup, etc.
// Note: I didn't provide <vm/vm_param.h>
#ifndef __BSD_VISIBLE
#define __BSD_VISIBLE
#define __BSD_VISIBLE 1
#endif
/*-

View File

@ -147,7 +147,6 @@ Result socketGetLastSfdnsresResult(void) {
return g_sfdnsresResult;
}
/********************************************* BSD:U FUNCTIONS AND RELATED *********************************************/
/***********************************************************************************************************************/
static int _socketGetFd(int fd) {
@ -659,8 +658,6 @@ int recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags, s
return -1;
}
/****************************************** ARPA/INET.H FUNCTIONS AND RELATED ******************************************/
/***********************************************************************************************************************/
// Adapted from ctrulib
@ -1057,7 +1054,6 @@ in_addr_t inet_addr(const char *cp) {
return addr.s_addr;
}
/******************************************** NETDB.H FUNCTIONS AND RELATED ********************************************/
/***********************************************************************************************************************/
static struct hostent *_socketDeserializeHostent(int *err, const void *out_he_serialized) {
@ -1539,7 +1535,6 @@ void sethostent(int a) { (void)a;}
void setnetent(int a) { (void)a;}
void setprotoent(int a) { (void)a; }
/******************************************** UNISTD.H FUNCTIONS AND RELATED ********************************************/
/************************************************************************************************************************/
long gethostid(void) {

View File

@ -2,14 +2,6 @@
#include <errno.h>
#include <string.h>
#include "types.h"
#include "result.h"
#include "ipc.h"
#include "services/bsd.h"
#include "services/sm.h"
#include "kernel/shmem.h"
#include "kernel/rwlock.h"
// Complete definition of struct timeout:
#include <sys/time.h>
@ -20,6 +12,14 @@
#include <net/if.h>
#include <net/if_media.h>
#include "types.h"
#include "result.h"
#include "ipc.h"
#include "services/bsd.h"
#include "services/sm.h"
#include "kernel/shmem.h"
#include "kernel/rwlock.h"
__thread Result g_bsdResult;
__thread int g_bsdErrno;

View File

@ -102,7 +102,6 @@ Result sfdnsresGetHostByName(SfdnsresRequestResults *ret, const SfdnsresConfig *
IpcCommand c;
ipcInitialize(&c);
ipcAddSendBuffer(&c, name, name == NULL ? 0 : strlen(name) + 1, 0);
ipcAddRecvBuffer(&c, out_he_serialized, config->serialized_out_hostent_max_size, 0);
return _sfdnsresDnsRequestCommand(&c, 2, ret, config, true, NULL);