Networking: PKT logic now uses the device event list

This commit is contained in:
Gregory Nutt 2015-05-28 12:40:05 -06:00
parent cc1469a364
commit d319b7c6f0
3 changed files with 30 additions and 21 deletions

View File

@ -52,8 +52,8 @@
/* Allocate a new packet socket data callback */
#define pkt_callback_alloc(conn) devif_callback_alloc(NULL, &conn->list)
#define pkt_callback_free(conn,cb) devif_callback_free(NULL, cb, &conn->list)
#define pkt_callback_alloc(dev,conn) devif_callback_alloc(dev, &conn->list)
#define pkt_callback_free(dev,conn,cb) devif_callback_free(dev, cb, &conn->list)
/****************************************************************************
* Public Type Definitions

View File

@ -213,6 +213,7 @@ static uint16_t psock_send_interrupt(FAR struct net_driver_s *dev,
ssize_t psock_pkt_send(FAR struct socket *psock, FAR const void *buf,
size_t len)
{
FAR struct net_driver_s *dev;
struct send_s state;
net_lock_t save;
int err;
@ -226,6 +227,16 @@ ssize_t psock_pkt_send(FAR struct socket *psock, FAR const void *buf,
goto errout;
}
/* Get the device driver that will service this transfer */
/* TODO better lookup network interface from *psock or *conn */
dev = netdev_findbyname("eth0");
if (dev == NULL)
{
err = ENODEV;
goto errout;
}
/* Set the socket state to sending */
psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_SEND);
@ -250,29 +261,18 @@ ssize_t psock_pkt_send(FAR struct socket *psock, FAR const void *buf,
/* Allocate resource to receive a callback */
state.snd_cb = pkt_callback_alloc(conn);
state.snd_cb = pkt_callback_alloc(dev, conn);
if (state.snd_cb)
{
FAR struct net_driver_s *dev;
/* Set up the callback in the connection */
state.snd_cb->flags = PKT_POLL;
state.snd_cb->priv = (void*)&state;
state.snd_cb->event = psock_send_interrupt;
/* Notify the device driver of the availability of TX data */
/* TODO better lookup network interface from *psock or *conn */
/* Notify the device driver that new TX data is available. */
dev = netdev_findbyname("eth0");
/* Notify the device driver that new TX data is available.
* NOTES: This is in essence what netdev_ipv4_txnotify() does,
* which is not possible to call since it expects a in_addr_t as
* its single argument to lookup the network interface.
*/
dev->d_txavail(dev);
netdev_txnotify_dev(dev);
/* Wait for the send to complete or an error to occur: NOTES: (1)
* net_lockedwait will also terminate if a signal is received, (2)
@ -284,7 +284,7 @@ ssize_t psock_pkt_send(FAR struct socket *psock, FAR const void *buf,
/* Make sure that no further interrupts are processed */
pkt_callback_free(conn, state.snd_cb);
pkt_callback_free(dev, conn, state.snd_cb);
}
}

View File

@ -1300,6 +1300,7 @@ static ssize_t pkt_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
FAR struct sockaddr *from, FAR socklen_t *fromlen)
{
FAR struct pkt_conn_s *conn = (FAR struct pkt_conn_s *)psock->s_conn;
FAR struct net_driver_s *dev;
struct recvfrom_s state;
net_lock_t save;
int ret;
@ -1314,6 +1315,16 @@ static ssize_t pkt_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
save = net_lock();
recvfrom_init(psock, buf, len, from, fromlen, &state);
/* Get the device driver that will service this transfer */
/* TODO better lookup network interface from *psock or *conn */
dev = netdev_findbyname("eth0");
if (dev == NULL)
{
err = ENODEV;
goto errout_with_state;
}
/* TODO recvfrom_init() expects from to be of type sockaddr_in, but
* in our case is sockaddr_ll
*/
@ -1328,7 +1339,7 @@ static ssize_t pkt_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Set up the callback in the connection */
state.rf_cb = pkt_callback_alloc(conn);
state.rf_cb = pkt_callback_alloc(dev, conn);
if (state.rf_cb)
{
state.rf_cb->flags = (PKT_NEWDATA | PKT_POLL);
@ -1351,7 +1362,7 @@ static ssize_t pkt_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Make sure that no further interrupts are processed */
pkt_callback_free(conn, state.rf_cb);
pkt_callback_free(dev, conn, state.rf_cb);
ret = recvfrom_result(ret, &state);
}
else
@ -1359,9 +1370,7 @@ static ssize_t pkt_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
ret = -EBUSY;
}
#if 0 /* Not used */
errout_with_state:
#endif
net_unlock(save);
recvfrom_uninit(&state);
return ret;