Unix domain: Various fixes to get apps/examplex/udgram working

This commit is contained in:
Gregory Nutt 2015-01-29 11:05:04 -06:00
parent e5f820a2cd
commit 0deca5b039
6 changed files with 31 additions and 20 deletions

View File

@ -502,7 +502,8 @@ int local_create_fifos(FAR struct local_conn_s *conn);
*
****************************************************************************/
int local_create_halfduplex(FAR struct local_conn_s *conn);
int local_create_halfduplex(FAR struct local_conn_s *conn,
FAR const char *path);
/****************************************************************************
* Name: local_destroy_fifos
@ -582,7 +583,7 @@ int local_open_receiver(FAR struct local_conn_s *conn);
*
****************************************************************************/
int local_open_sender(FAR struct local_conn_s *conn, FAR char *path);
int local_open_sender(FAR struct local_conn_s *conn, FAR const char *path);
#undef EXTERN
#ifdef __cplusplus

View File

@ -320,14 +320,14 @@ int local_create_fifos(FAR struct local_conn_s *conn)
*
****************************************************************************/
int local_create_halfduplex(FAR struct local_conn_s *conn)
int local_create_halfduplex(FAR struct local_conn_s *conn, FAR const char *path)
{
char path[LOCAL_FULLPATH_LEN];
char fullpath[LOCAL_FULLPATH_LEN];
/* Create the half duplex FIFO if it does not already exist. */
local_hd_name(conn->lc_path, path);
return local_create_fifo(path);
local_hd_name(path, fullpath);
return local_create_fifo(fullpath);
}
/****************************************************************************
@ -490,7 +490,7 @@ int local_open_receiver(FAR struct local_conn_s *conn)
*
****************************************************************************/
int local_open_sender(FAR struct local_conn_s *conn, FAR char *path)
int local_open_sender(FAR struct local_conn_s *conn, FAR const char *path)
{
char fullpath[LOCAL_FULLPATH_LEN];

View File

@ -266,7 +266,7 @@ psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Make sure that half duplex FIFO has been created */
ret = local_create_halfduplex(conn);
ret = local_create_halfduplex(conn, conn->lc_path);
if (ret < 0)
{
ndbg("ERROR: Failed to create FIFO for %s: %d\n",

View File

@ -152,7 +152,7 @@ int local_send_packet(int fd, FAR const uint8_t *buf, size_t len)
len16 = len;
ret = local_fifo_write(fd, (FAR const uint8_t *)&len16, sizeof(uint16_t));
if(ret == OK)
if (ret == OK)
{
/* Send the packet data */

View File

@ -95,13 +95,17 @@ ssize_t psock_local_sendto(FAR struct socket *psock, FAR const void *buf,
DEBUGASSERT(buf && len <= UINT16_MAX);
/* Verify that this is a bound, un-connected peer socket */
/* Verify that this is not a connected peer socket. It need not be
* bound, however. If unbound, recvfrom will see this as a nameless
* connection.
*/
if (conn->lc_state != LOCAL_STATE_BOUND)
if (conn->lc_state != LOCAL_STATE_UNBOUND &&
conn->lc_state != LOCAL_STATE_BOUND)
{
/* Either not bound to address or it is connected */
ndbg("ERROR: Connected or not bound\n");
ndbg("ERROR: Connected state\n");
return -EISCONN;
}
@ -122,7 +126,7 @@ ssize_t psock_local_sendto(FAR struct socket *psock, FAR const void *buf,
* REVISIT: Or should be just make sure that it already exists?
*/
ret = local_create_halfduplex(conn);
ret = local_create_halfduplex(conn, unaddr->sun_path);
if (ret < 0)
{
ndbg("ERROR: Failed to create FIFO for %s: %d\n",
@ -147,6 +151,12 @@ ssize_t psock_local_sendto(FAR struct socket *psock, FAR const void *buf,
{
ndbg("ERROR: Failed to send the packet: %d\n", ret);
}
else
{
/* local_send_packet returns 0 if all 'len' bytes were sent */
nsent = len;
}
/* Now we can close the write-only socket descriptor */

View File

@ -127,7 +127,7 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
{
socklen_t minlen;
#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_LOCAL)
int ret;
ssize_t nsent;
#endif
int err;
@ -209,7 +209,7 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
if (psock->s_domain == PF_LOCAL)
#endif
{
ret = psock_local_sendto(psock, buf, len, flags, to, tolen);
nsent = psock_local_sendto(psock, buf, len, flags, to, tolen);
}
#endif /* CONFIG_NET_LOCAL */
@ -218,20 +218,20 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
else
#endif
{
ret = psock_udp_sendto(psock, buf, len, flags, to, tolen);
nsent = psock_udp_sendto(psock, buf, len, flags, to, tolen);
}
#endif /* CONFIG_NET_UDP */
/* Check if the domain-specific sendto() logic failed */
if (ret < 0)
if (nsent < 0)
{
ndbg("ERROR: Domain sendto() failed: %d\n", ret);
err = -ret;
ndbg("ERROR: Unix domain sendto() failed: %d\n", ret);
err = -nsent;
goto errout;
}
return OK;
return nsent;
#else
err = ENOSYS;
#endif /* CONFIG_NET_UDP || CONFIG_NET_LOCAL */