mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 11:56:10 +08:00
Unix domain: More fixes. With these changes, apps/examples/ustream works
This commit is contained in:
@@ -26,10 +26,14 @@ nanosleep NXnanosleep
|
|||||||
pthread_create NXpthread_create
|
pthread_create NXpthread_create
|
||||||
read NXread
|
read NXread
|
||||||
realloc NXrealloc
|
realloc NXrealloc
|
||||||
|
recv NXrecv
|
||||||
|
recvfrom NXrecvfrom
|
||||||
rewinddir NXrewinddir
|
rewinddir NXrewinddir
|
||||||
rmdir NXrmdir
|
rmdir NXrmdir
|
||||||
seekdir NXseekdir
|
seekdir NXseekdir
|
||||||
select NXselect
|
select NXselect
|
||||||
|
send NXsend
|
||||||
|
sendto NXsendto
|
||||||
sleep NXsleep
|
sleep NXsleep
|
||||||
socket NXsocket
|
socket NXsocket
|
||||||
stat NXstat
|
stat NXstat
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ int inline local_stream_connect(FAR struct local_conn_s *client,
|
|||||||
|
|
||||||
/* Yes.. open the read-only FIFO */
|
/* Yes.. open the read-only FIFO */
|
||||||
|
|
||||||
ret = local_open_client_tx(client);
|
ret = local_open_client_rx(client);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
ndbg("ERROR: Failed to open write-only FIFOs for %s: %d\n",
|
ndbg("ERROR: Failed to open write-only FIFOs for %s: %d\n",
|
||||||
@@ -268,21 +268,27 @@ int local_connect(FAR struct local_conn_s *client,
|
|||||||
{
|
{
|
||||||
if (strncmp(conn->lc_path, unaddr->sun_path, UNIX_PATH_MAX-1) == 0)
|
if (strncmp(conn->lc_path, unaddr->sun_path, UNIX_PATH_MAX-1) == 0)
|
||||||
{
|
{
|
||||||
|
int ret = OK;
|
||||||
|
|
||||||
/* Bind the address and protocol */
|
/* Bind the address and protocol */
|
||||||
|
|
||||||
client->lc_proto = conn->lc_proto;
|
client->lc_proto = conn->lc_proto;
|
||||||
strncpy(client->lc_path, unaddr->sun_path, UNIX_PATH_MAX-1);
|
strncpy(client->lc_path, unaddr->sun_path, UNIX_PATH_MAX-1);
|
||||||
client->lc_path[UNIX_PATH_MAX-1] = '\0';
|
client->lc_path[UNIX_PATH_MAX-1] = '\0';
|
||||||
|
|
||||||
|
/* The client is now bound to an address */
|
||||||
|
|
||||||
|
client->lc_state = LOCAL_STATE_BOUND;
|
||||||
|
|
||||||
/* We have to do more for the SOCK_STREAM family */
|
/* We have to do more for the SOCK_STREAM family */
|
||||||
|
|
||||||
if (conn->lc_proto == SOCK_STREAM)
|
if (conn->lc_proto == SOCK_STREAM)
|
||||||
{
|
{
|
||||||
return local_stream_connect(client, conn, state);
|
ret = local_stream_connect(client, conn, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
net_unlock(state);
|
net_unlock(state);
|
||||||
return OK;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -237,8 +237,8 @@ static inline int local_rx_open(FAR struct local_conn_s *conn,
|
|||||||
static inline int local_tx_open(FAR struct local_conn_s *conn,
|
static inline int local_tx_open(FAR struct local_conn_s *conn,
|
||||||
FAR const char *path)
|
FAR const char *path)
|
||||||
{
|
{
|
||||||
conn->lc_infd = open(path, O_WRONLY);
|
conn->lc_outfd = open(path, O_WRONLY);
|
||||||
if (conn->lc_infd < 0)
|
if (conn->lc_outfd < 0)
|
||||||
{
|
{
|
||||||
int errcode = errno;
|
int errcode = errno;
|
||||||
DEBUGASSERT(errcode > 0);
|
DEBUGASSERT(errcode > 0);
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ ssize_t psock_local_recvfrom(FAR struct socket *psock, FAR void *buf,
|
|||||||
* the size of the next packet.
|
* the size of the next packet.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = local_sync(conn->lc_infd);
|
ret = local_sync(conn->lc_infd);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
ndbg("ERROR: Failed to get packet length: %d\n", ret);
|
ndbg("ERROR: Failed to get packet length: %d\n", ret);
|
||||||
|
|||||||
@@ -76,16 +76,16 @@
|
|||||||
|
|
||||||
int local_fifo_read(int fd, FAR uint8_t *buf, size_t *len)
|
int local_fifo_read(int fd, FAR uint8_t *buf, size_t *len)
|
||||||
{
|
{
|
||||||
ssize_t total;
|
ssize_t remaining;
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(buf && len);
|
DEBUGASSERT(buf && len);
|
||||||
|
|
||||||
total = 0;
|
remaining = *len;
|
||||||
while (len > 0)
|
while (remaining > 0)
|
||||||
{
|
{
|
||||||
nread = read(fd, buf, *len);
|
nread = read(fd, buf, remaining);
|
||||||
if (nread < 0)
|
if (nread < 0)
|
||||||
{
|
{
|
||||||
int errcode = errno;
|
int errcode = errno;
|
||||||
@@ -112,15 +112,15 @@ int local_fifo_read(int fd, FAR uint8_t *buf, size_t *len)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
DEBUGASSERT(nread <= len);
|
DEBUGASSERT(nread <= len);
|
||||||
len -= nread;
|
remaining -= nread;
|
||||||
buf += nread;
|
buf += nread;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = OK;
|
ret = OK;
|
||||||
|
|
||||||
errout:
|
errout:
|
||||||
*len = total;
|
*len -= remaining;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ ssize_t psock_local_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
size_t len, int flags)
|
size_t len, int flags)
|
||||||
{
|
{
|
||||||
FAR struct local_conn_s *peer;
|
FAR struct local_conn_s *peer;
|
||||||
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(psock && psock->s_conn && buf);
|
DEBUGASSERT(psock && psock->s_conn && buf);
|
||||||
peer = (FAR struct local_conn_s *)psock->s_conn;
|
peer = (FAR struct local_conn_s *)psock->s_conn;
|
||||||
@@ -84,14 +85,20 @@ ssize_t psock_local_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
* outgoing FIFO for write-only access.
|
* outgoing FIFO for write-only access.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (peer->lc_type != LOCAL_STATE_CONNECTED ||
|
if (peer->lc_state != LOCAL_STATE_CONNECTED ||
|
||||||
peer->lc_outfd < 0)
|
peer->lc_outfd < 0)
|
||||||
{
|
{
|
||||||
ndbg("ERROR: not connected\n");
|
ndbg("ERROR: not connected\n");
|
||||||
return -ENOTCONN;
|
return -ENOTCONN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return local_send_packet(peer->lc_outfd, (FAR uint8_t *)buf, len);
|
/* Send the packet */
|
||||||
|
|
||||||
|
ret = local_send_packet(peer->lc_outfd, (FAR uint8_t *)buf, len);
|
||||||
|
|
||||||
|
/* If the send was successful, then the full packet will have been sent */
|
||||||
|
|
||||||
|
return ret < 0 ? ret : len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_NET && CONFIG_NET_LOCAL */
|
#endif /* CONFIG_NET && CONFIG_NET_LOCAL */
|
||||||
|
|||||||
+2
-2
@@ -38,7 +38,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
#if defined(CONFIG_NET) && defined(CONFIG_NET_TCP)
|
#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_LOCAL)
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
@@ -243,4 +243,4 @@ ssize_t send(int sockfd, FAR const void *buf, size_t len, int flags)
|
|||||||
return psock_send(sockfd_socket(sockfd), buf, len, flags);
|
return psock_send(sockfd_socket(sockfd), buf, len, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_NET && CONFIG_NET_TCP */
|
#endif /* CONFIG_NET_TCP || CONFIG_NET_LOCAL */
|
||||||
|
|||||||
Reference in New Issue
Block a user