Add support for sendCOMM method
Credits go to user @angelsware, I just did a copy/paste from #120
This commit is contained in:
@@ -973,3 +973,40 @@ int sendVIEW(XPCSocket sock, VIEW_TYPE view)
|
||||
/*****************************************************************************/
|
||||
/**** End View functions ****/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/**** Comm functions ****/
|
||||
/*****************************************************************************/
|
||||
int sendCOMM(XPCSocket sock, const char* comm) {
|
||||
// Setup command
|
||||
// Max size is technically unlimited.
|
||||
unsigned char buffer[65536] = "COMM";
|
||||
int pos = 5;
|
||||
|
||||
int commLen = strnlen(comm, 256);
|
||||
if (pos + commLen + 2 > 65536)
|
||||
{
|
||||
printError("sendCOMM", "About to overrun the send buffer!");
|
||||
return -4;
|
||||
}
|
||||
if (commLen > 255)
|
||||
{
|
||||
printError("sendCOMM", "comm is too long. Must be less than 256 characters.");
|
||||
return -1;
|
||||
}
|
||||
// Copy comm to buffer
|
||||
buffer[pos++] = (unsigned char)commLen;
|
||||
memcpy(buffer + pos, comm, commLen);
|
||||
pos += commLen;
|
||||
|
||||
// Send command
|
||||
if (sendUDP(sock, buffer, pos) < 0)
|
||||
{
|
||||
printError("setDREF", "Failed to send command");
|
||||
return -3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*****************************************************************************/
|
||||
/**** End Comm functions ****/
|
||||
/*****************************************************************************/
|
||||
@@ -303,6 +303,13 @@ int sendVIEW(XPCSocket sock, VIEW_TYPE view);
|
||||
/// \returns 0 if successful, otherwise a negative value.
|
||||
int sendWYPT(XPCSocket sock, WYPT_OP op, float points[], int count);
|
||||
|
||||
/// Sends commands.
|
||||
///
|
||||
/// \param sock The socket to use to send the command.
|
||||
/// \param comm The command string.
|
||||
/// \returns 0 if successful, otherwise a negative value.
|
||||
int sendCOMM(XPCSocket sock, const char* comm);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user