mirror of https://github.com/nirenjan/libx52.git
Fix x52d_send_command prototype
Prior to this change, the recv call was using the same buflen as that of the send, which meant that the response would be truncated at by the client, while the server was sending the entire message. This was evident by running a Python client which manually called recv with the maximum buffer size. This change updates the prototype to take both a bufin (length of the input buffer), and a bufout (length of the output buffer) argument, instead of a single buflen. With this change, commands work as expected in x52ctl.reverse-scroll
parent
116b9e2c0c
commit
20abe8974c
|
@ -71,7 +71,7 @@ static int send_command(int sock_fd, int argc, char **argv)
|
||||||
buflen += arglen;
|
buflen += arglen;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = x52d_send_command(sock_fd, buffer, buflen);
|
rc = x52d_send_command(sock_fd, buffer, buflen, sizeof(buffer));
|
||||||
if (rc >= 0) {
|
if (rc >= 0) {
|
||||||
if (write(STDOUT_FILENO, buffer, rc) < 0) {
|
if (write(STDOUT_FILENO, buffer, rc) < 0) {
|
||||||
perror("write");
|
perror("write");
|
||||||
|
|
|
@ -51,7 +51,7 @@ int x52d_dial_command(const char *sock_path)
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
int x52d_send_command(int sock_fd, char *buffer, size_t buflen)
|
int x52d_send_command(int sock_fd, char *buffer, size_t bufin, size_t bufout)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ int x52d_send_command(int sock_fd, char *buffer, size_t buflen)
|
||||||
* Unix sockets should have sufficient capacity to send the full
|
* Unix sockets should have sufficient capacity to send the full
|
||||||
* datagram in a single message. Assume that is the case.
|
* datagram in a single message. Assume that is the case.
|
||||||
*/
|
*/
|
||||||
rc = send(sock_fd, buffer, buflen, 0);
|
rc = send(sock_fd, buffer, bufin, 0);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
// Error
|
// Error
|
||||||
if (errno == EINTR) {
|
if (errno == EINTR) {
|
||||||
|
@ -77,7 +77,7 @@ int x52d_send_command(int sock_fd, char *buffer, size_t buflen)
|
||||||
|
|
||||||
/* Wait till we get a response */
|
/* Wait till we get a response */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
rc = recv(sock_fd, buffer, buflen, 0);
|
rc = recv(sock_fd, buffer, bufout, 0);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
// Error
|
// Error
|
||||||
if (errno == EINTR) {
|
if (errno == EINTR) {
|
||||||
|
|
|
@ -75,12 +75,13 @@ int x52d_dial_command(const char *sock_path);
|
||||||
* parameters. This is also used to save the returned
|
* parameters. This is also used to save the returned
|
||||||
* response.
|
* response.
|
||||||
*
|
*
|
||||||
* @param[in] buflen Length of the buffer to hold the returned response.
|
* @param[in] bufin Length of the command in the input buffer
|
||||||
|
* @param[in] bufout Maximum length of the response
|
||||||
*
|
*
|
||||||
* @returns number of bytes returned from the server
|
* @returns number of bytes returned from the server
|
||||||
* @returns -1 on an error condition, and \c errno is set accordingly.
|
* @returns -1 on an error condition, and \c errno is set accordingly.
|
||||||
*/
|
*/
|
||||||
int x52d_send_command(int sock_fd, char *buffer, size_t buflen);
|
int x52d_send_command(int sock_fd, char *buffer, size_t bufin, size_t bufout);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Reference in New Issue