Writing to the NvSciIpc Endpoint

The follow example shows how to write to the NvSciIpc endpoint.

Write to NvSciIpc channel

NvSciIpcEndpoint ipcEndpoint;
struct NvSciIpcEndpointInfo info;
int32_t fd;
fd_set rfds;
uint32_t event = 0;
void *buf;
uint32_t buf_size, bytes;
int retval;
NvSciError err;
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
buf = malloc(info.frame_size);
if (buf == NULL) {
    goto fail;
}   
while (1) {
       err = NvSciIpcGetEventSafe(ipcEndpoint, &event);
       if (err != NvSciError_Success) {
                goto fail;
       }
       if (event & NV_SCI_IPC_EVENT_WRITE) {
               /* Assuming buf contains the pointer to data to be written.
                * buf_size contains the size of data. It should be less than
                * Endpoint frame size.
                */
               err = NvSciIpcWrite(ipcEndpoint, buf, buf_size, &bytes);
               if(err != NvSciError_Success) {
                      printf("error in writing endpoint\n");
                      goto fail;
               }                      
       } else {                       
               retval = select(fd + 1, &rfds, NULL, NULL, NULL);
               if ((retval < 0) & (retval != EINTR)) {                      
                       exit(-1);
               }              
        }
}