Commit 40744e91 authored by Jussi Kivilinna's avatar Jussi Kivilinna
Browse files

ubgps: use write wrapper when expecting to succeed writing buffer fully


Signed-off-by: default avatarJussi Kivilinna <jussi.kivilinna@haltian.com>
parent a5a664fe
......@@ -1685,6 +1685,37 @@ void __ubgps_gc_callbacks(struct ubgps_s * const gps)
}
}
/****************************************************************************
* Name: __ubgps_full_write
****************************************************************************/
size_t __ubgps_full_write(int gps_fd, const void *buf, size_t writelen)
{
const uint8_t *writebuf = buf;
size_t nwritten;
size_t total = 0;
do
{
nwritten = write(gps_fd, writebuf, writelen);
if (nwritten == ERROR)
{
int error = get_errno();
if (error != EAGAIN)
{
return ERROR;
}
nwritten = 0;
}
writebuf += nwritten;
writelen -= nwritten;
total += nwritten;
}
while (writelen > 0);
return total;
}
/****************************************************************************
* Name: ubgps_check_alp_file_validity
*
......
......@@ -702,6 +702,12 @@ void __ubgps_gc_callbacks(struct ubgps_s * const gps);
bool ubgps_check_alp_file_validity(const char *filepath);
/****************************************************************************
* Name: __ubgps_full_write
****************************************************************************/
size_t __ubgps_full_write(int gps_fd, const void *buf, size_t writelen);
#ifdef CONFIG_UBGPS_ASSIST_UPDATER
/****************************************************************************
......
......@@ -295,7 +295,7 @@ int ubx_msg_send(struct ubgps_s * const gps, const int fd, struct ubx_msg_s cons
/* Send UBX sync characters */
ret = write(fd, header, sizeof(header));
ret = __ubgps_full_write(fd, header, sizeof(header));
if (ret != sizeof(header))
return ERROR;
......@@ -311,7 +311,7 @@ int ubx_msg_send(struct ubgps_s * const gps, const int fd, struct ubx_msg_s cons
printf("\n");
#endif /* UBX_DEBUG */
ret = write(fd, msg, msg_len);
ret = __ubgps_full_write(fd, msg, msg_len);
if (ret != msg_len)
return ERROR;
......@@ -329,7 +329,7 @@ int ubx_msg_send(struct ubgps_s * const gps, const int fd, struct ubx_msg_s cons
checksum[0] = ck_a;
checksum[1] = ck_b;
ret = write(fd, checksum, sizeof(checksum));
ret = __ubgps_full_write(fd, checksum, sizeof(checksum));
if (ret != sizeof(checksum))
return ERROR;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment