tcp_socket.c File Reference

TCP sockect with kfile interface. More...

#include "tcp_socket.h"
#include "cfg/cfg_tcpsocket.h"
#include <cfg/log.h>
#include <cpu/byteorder.h>
#include <lwip/ip_addr.h>
#include <lwip/api.h>
#include <lwip/netif.h>
#include <lwip/netbuf.h>
#include <lwip/tcpip.h>

Go to the source code of this file.

Functions

void tcpsocket_serverPoll (KFile *fd)
 Process all received connection from socket.
void tcpsocket_init (TcpSocket *socket, struct ip_addr *local_addr, struct ip_addr *remote_addr, uint16_t port)
 Init tcp socket connection with kfile interface.
void tcpsocket_serverInit (TcpSocket *socket, struct ip_addr *local_addr, struct ip_addr *listen_addr, uint16_t port, tcphandler_t handler)
 Init tcp server whit kfile interface.

Detailed Description

TCP sockect with kfile interface.

Author:
Luca Ottaviano <lottaviano@develer.com>
Daniele Basile <asterix@develer.com>

Definition in file tcp_socket.c.


Function Documentation

void tcpsocket_init ( TcpSocket *  socket,
struct ip_addr *  local_addr,
struct ip_addr *  remote_addr,
uint16_t  port 
)

Init tcp socket connection with kfile interface.

Note:
the real connection will be performed only when we do the first kfile_read(). The read function is blocking and receive timeout is not settable, this depends to the current version of lwip.
Parameters:
sockettcp socket context.
local_addrdevice ip address.
remote_addrip address that we would connect.
porttcp port that we would connect.

Definition at line 297 of file tcp_socket.c.

void tcpsocket_serverInit ( TcpSocket *  socket,
struct ip_addr *  local_addr,
struct ip_addr *  listen_addr,
uint16_t  port,
tcphandler_t  handler 
)

Init tcp server whit kfile interface.

Start a tcp server on registered ethernet interface, and it calls the user handler when receive data from accepted connection socket.

Note:
Use the tcpsocket_serverPoll() function to process al connections.
Parameters:
sockettcp socket context.
local_addrdevice ip address.
listen_addrip address to listen
porttcp socket port to listen
handleruser handler that server calls every time we recive a data from socket. To the handler the server will pass the kfile context and user could choose to make an explicit connection close, otherwise the server keep alive the connection.

Definition at line 331 of file tcp_socket.c.

void tcpsocket_serverPoll ( KFile fd)

Process all received connection from socket.

Parameters:
fdopened tcp socket server kfile context.

Definition at line 269 of file tcp_socket.c.