mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 16:50:55 +08:00
Implement TCP send; remove uIP proto-sockets
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@339 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+5
-44
@@ -28,51 +28,12 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __HTTPD_H__
|
||||
#define __HTTPD_H__
|
||||
#ifndef _NET_UIP_HTTPD_H
|
||||
#define _NET_UIP_HTTPD_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <net/uip/psock.h>
|
||||
|
||||
#define HTTPD_FS_STATISTICS 1
|
||||
extern void httpd_init(void);
|
||||
extern void httpd_listen(void);
|
||||
|
||||
struct httpd_fs_file
|
||||
{
|
||||
char *data;
|
||||
int len;
|
||||
};
|
||||
|
||||
struct httpd_state
|
||||
{
|
||||
unsigned char timer;
|
||||
struct psock sin, sout;
|
||||
char inputbuf[50];
|
||||
char filename[20];
|
||||
char state;
|
||||
struct httpd_fs_file file;
|
||||
int len;
|
||||
char *scriptptr;
|
||||
int scriptlen;
|
||||
|
||||
unsigned short count;
|
||||
};
|
||||
|
||||
#ifdef HTTPD_FS_STATISTICS
|
||||
#if HTTPD_FS_STATISTICS == 1
|
||||
extern uint16 httpd_fs_count(char *name);
|
||||
#endif /* HTTPD_FS_STATISTICS */
|
||||
#endif /* HTTPD_FS_STATISTICS */
|
||||
|
||||
void httpd_init(void);
|
||||
void httpd_log(char *msg);
|
||||
void httpd_log_file(uint16 *requester, char *file);
|
||||
|
||||
/* file must be allocated by caller and will be filled in
|
||||
* by the function.
|
||||
*/
|
||||
|
||||
int httpd_fs_open(const char *name, struct httpd_fs_file *file);
|
||||
void httpd_fs_init(void);
|
||||
|
||||
|
||||
#endif /* __HTTPD_H__ */
|
||||
#endif /* _NET_UIP_HTTPD_H */
|
||||
|
||||
@@ -1,257 +0,0 @@
|
||||
/****************************************************************************
|
||||
* psock.h
|
||||
* Protosocket library header file
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* This logic was leveraged from uIP which also has a BSD-style license:
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
* Copyright (c) 2004, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __NET_UIP_PSOCK_H
|
||||
#define __NET_UIP_PSOCK_H
|
||||
|
||||
/* psock Protosockets library
|
||||
*
|
||||
* The protosocket library provides an interface to the uIP stack that is
|
||||
* similar to the traditional BSD socket interface. Unlike programs
|
||||
* written for the ordinary uIP event-driven interface, programs
|
||||
* written with the protosocket library are executed in a sequential
|
||||
* fashion and does not have to be implemented as explicit state
|
||||
* machines.
|
||||
*
|
||||
* Protosockets only work with TCP connections.
|
||||
*
|
||||
* The protosocket library uses \ref pt protothreads to provide
|
||||
* sequential control flow. This makes the protosockets lightweight in
|
||||
* terms of memory, but also means that protosockets inherits the
|
||||
* functional limitations of protothreads. Each protosocket lives only
|
||||
* within a single function. Automatic variables (stack variables) are
|
||||
* not retained across a protosocket library function call.
|
||||
*
|
||||
* \note Because the protosocket library uses protothreads, local
|
||||
* variables will not always be saved across a call to a protosocket
|
||||
* library function. It is therefore advised that local variables are
|
||||
* used with extreme care.
|
||||
*
|
||||
* The protosocket library provides functions for sending data without
|
||||
* having to deal with retransmissions and acknowledgements, as well
|
||||
* as functions for reading data without having to deal with data
|
||||
* being split across more than one TCP segment.
|
||||
*
|
||||
* Because each protosocket runs as a protothread, the protosocket has to be
|
||||
* started with a call to PSOCK_BEGIN() at the start of the function
|
||||
* in which the protosocket is used. Similarly, the protosocket protothread can
|
||||
* be terminated by a call to PSOCK_EXIT().
|
||||
*
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#ifdef CONFIG_NET
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <net/uip/uipopt.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* The structure that holds the state of a buffer.
|
||||
*
|
||||
* This structure holds the state of a uIP buffer. The structure has
|
||||
* no user-visible elements, but is used through the functions
|
||||
* provided by the library.
|
||||
*
|
||||
*/
|
||||
|
||||
struct psock_buf
|
||||
{
|
||||
uint8 *ptr;
|
||||
unsigned short left;
|
||||
};
|
||||
|
||||
/* The representation of a protosocket.
|
||||
*
|
||||
* The protosocket structrure is an opaque structure with no user-visible
|
||||
* elements.
|
||||
*/
|
||||
|
||||
struct psock
|
||||
{
|
||||
const uint8 *sendptr; /* Pointer to the next data to be sent. */
|
||||
uint8 *readptr; /* Pointer to the next data to be read. */
|
||||
uint8 *bufptr; /* Pointer to the buffer used for buffering incoming data. */
|
||||
uint16 sendlen; /* The number of bytes left to be sent. */
|
||||
uint16 readlen; /* The number of bytes left to be read. */
|
||||
struct psock_buf buf; /* The structure holding the state of the input buffer. */
|
||||
unsigned int bufsize; /* The size of the input buffer. */
|
||||
unsigned char state; /* The state of the protosocket. */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public FunctionPrototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* Initialize a protosocket.
|
||||
*
|
||||
* Initializes a protosocket and must be called before the
|
||||
* protosocket is used. The initialization also specifies the input buffer
|
||||
* for the protosocket.
|
||||
*
|
||||
* psock (struct psock *) A pointer to the protosocket to be
|
||||
* initialized
|
||||
*
|
||||
* buffer (char *) A pointer to the input buffer for the
|
||||
* protosocket.
|
||||
*
|
||||
* buffersize (unsigned int) The size of the input buffer.
|
||||
*/
|
||||
|
||||
extern void psock_init(struct psock *psock, char *buffer, unsigned int buffersize);
|
||||
|
||||
/* Send data.
|
||||
*
|
||||
* This macro sends data over a protosocket. The protosocket protothread blocks
|
||||
* until all data has been sent and is known to have been received by
|
||||
* the remote end of the TCP connection.
|
||||
*
|
||||
* psock (struct psock *) A pointer to the protosocket over which
|
||||
* data is to be sent.
|
||||
*
|
||||
* data (char *) A pointer to the data that is to be sent.
|
||||
*
|
||||
* datalen (unsigned int) The length of the data that is to be
|
||||
* sent.
|
||||
*/
|
||||
|
||||
extern void psock_send(struct psock *psock, const char *buf, unsigned int len);
|
||||
|
||||
/*Send a null-terminated string.
|
||||
*
|
||||
* psock Pointer to the protosocket.
|
||||
* str The string to be sent.
|
||||
*
|
||||
* This function sends a null-terminated string over the
|
||||
* protosocket.
|
||||
*/
|
||||
|
||||
#define PSOCK_SEND_STR(psock, str) psock_send(psock, str, strlen(str))
|
||||
|
||||
/* Generate data with a function and send it
|
||||
*
|
||||
* psock Pointer to the protosocket.
|
||||
* generator Pointer to the generator function
|
||||
* arg Argument to the generator function
|
||||
*
|
||||
* This function generates data and sends it over the
|
||||
* protosocket. This can be used to dynamically generate
|
||||
* data for a transmission, instead of generating the data
|
||||
* in a buffer beforehand. This function reduces the need for
|
||||
* buffer memory. The generator function is implemented by
|
||||
* the application, and a pointer to the function is given
|
||||
* as an argument with the call to PSOCK_GENERATOR_SEND().
|
||||
*
|
||||
* The generator function should place the generated data
|
||||
* directly in the uip_appdata buffer, and return the
|
||||
* length of the generated data. The generator function is
|
||||
* called by the protosocket layer when the data first is
|
||||
* sent, and once for every retransmission that is needed.
|
||||
*/
|
||||
|
||||
extern void psock_generator_send(struct psock *psock, unsigned short (*f)(void *), void *arg);
|
||||
|
||||
/* Close a protosocket.
|
||||
*
|
||||
* This macro closes a protosocket and can only be called from within the
|
||||
* protothread in which the protosocket lives.
|
||||
*
|
||||
* psock (struct psock *) A pointer to the protosocket that is to
|
||||
* be closed.
|
||||
*/
|
||||
|
||||
#define PSOCK_CLOSE(psock) uip_close()
|
||||
|
||||
/* Read data until the buffer is full.
|
||||
*
|
||||
* This macro will block waiting for data and read the data into the
|
||||
* input buffer specified with the call to PSOCK_INIT(). Data is read
|
||||
* until the buffer is full..
|
||||
*
|
||||
* psock (struct psock *) A pointer to the protosocket from which
|
||||
* data should be read.
|
||||
*/
|
||||
|
||||
extern void psock_readbuf(struct psock *psock);
|
||||
|
||||
/* Read data up to a specified character.
|
||||
*
|
||||
* This macro will block waiting for data and read the data into the
|
||||
* input buffer specified with the call to PSOCK_INIT(). Data is only
|
||||
* read until the specifieed character appears in the data stream.
|
||||
*
|
||||
* psock (struct psock *) A pointer to the protosocket from which
|
||||
* data should be read.
|
||||
*
|
||||
* c (char) The character at which to stop reading.
|
||||
*/
|
||||
|
||||
extern void psock_readto(struct psock *psock, unsigned char c);
|
||||
|
||||
/* The length of the data that was previously read.
|
||||
*
|
||||
* Returns the length of the data that was previously read
|
||||
* using PSOCK_READTO() or PSOCK_READ().
|
||||
*
|
||||
* psock (struct psock *) A pointer to the protosocket holding the data.
|
||||
*/
|
||||
|
||||
extern uint16 psock_datalen(struct psock *psock);
|
||||
|
||||
/* Check if there is new data has arrived on a protosocket without blocking
|
||||
*
|
||||
* psock (struct psock *) A pointer to the protosocket.
|
||||
*/
|
||||
|
||||
extern boolean psock_checknewdata(struct psock *s);
|
||||
|
||||
/* Block until new data has arrived on a protosocket.
|
||||
*
|
||||
* psock (struct psock *) A pointer to the protosocket.
|
||||
*/
|
||||
|
||||
extern void psock_waitnewdata(struct psock *s);
|
||||
|
||||
#endif /* CONFIG_NET */
|
||||
#endif /* __NET_UIP_PSOCK_H */
|
||||
+1
-1
@@ -46,7 +46,6 @@
|
||||
#include <semaphore.h>
|
||||
|
||||
#include <net/uip/uip.h>
|
||||
#include <net/uip/psock.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
@@ -87,6 +86,7 @@ struct socket
|
||||
{
|
||||
int s_crefs; /* Reference count on the socket */
|
||||
uint8 s_type; /* Protocol type: Only SOCK_STREAM or SOCK_DGRAM */
|
||||
uint8 s_flags; /* See _SF_* definitions */
|
||||
#ifdef CONFIG_NET_SOCKOPTS
|
||||
sockopt_t s_options; /* Selected socket options */
|
||||
#ifndef CONFIG_DISABLE_CLOCK
|
||||
|
||||
+10
-10
@@ -177,21 +177,21 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
EXTERN int socket(int domain, int type, int protocol);
|
||||
EXTERN int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
|
||||
EXTERN int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
|
||||
EXTERN int bind(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen);
|
||||
EXTERN int connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen);
|
||||
|
||||
EXTERN ssize_t send(int sockfd, const void *buf, size_t len, int flags);
|
||||
EXTERN ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
|
||||
const struct sockaddr *to, socklen_t tolen);
|
||||
EXTERN ssize_t send(int sockfd, FAR const void *buf, size_t len, int flags);
|
||||
EXTERN ssize_t sendto(int sockfd, FAR const void *buf, size_t len, int flags,
|
||||
FAR const struct sockaddr *to, socklen_t tolen);
|
||||
|
||||
EXTERN ssize_t recv(int sockfd, void *buf, size_t len, int flags);
|
||||
EXTERN ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
|
||||
struct sockaddr *from, socklen_t *fromlen);
|
||||
EXTERN ssize_t recv(int sockfd, FAR void *buf, size_t len, int flags);
|
||||
EXTERN ssize_t recvfrom(int sockfd, FAR void *buf, size_t len, int flags,
|
||||
FAR struct sockaddr *from, FAR socklen_t *fromlen);
|
||||
|
||||
EXTERN int setsockopt(int sockfd, int level, int option,
|
||||
const void *value, socklen_t value_len);
|
||||
FAR const void *value, socklen_t value_len);
|
||||
EXTERN int getsockopt(int sockfd, int level, int option,
|
||||
void *value, socklen_t *value_len);
|
||||
FAR void *value, FAR socklen_t *value_len);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
|
||||
Reference in New Issue
Block a user