Fully operational prototype plugin. Fixed RX issues
This commit is contained in:
@@ -83,7 +83,7 @@ int zt_socket(SOCKET_SIG);
|
||||
int zt_connect(CONNECT_SIG);
|
||||
int zt_bind(BIND_SIG);
|
||||
#if defined(__linux__)
|
||||
int zt_accept(ACCEPT_SIG);
|
||||
int zt_accept4(ACCEPT_SIG);
|
||||
#endif
|
||||
int zt_accept(ACCEPT_SIG);
|
||||
int zt_listen(LISTEN_SIG);
|
||||
|
||||
@@ -53,6 +53,9 @@ extern "C" {
|
||||
|
||||
#define SERVICE_CONNECT_ATTEMPTS 30
|
||||
|
||||
ssize_t sock_fd_write(int sock, int fd);
|
||||
ssize_t sock_fd_read(int sock, void *buf, ssize_t bufsize, int *fd);
|
||||
|
||||
static int rpc_count;
|
||||
|
||||
static pthread_mutex_t lock;
|
||||
@@ -111,10 +114,6 @@ int load_symbols_rpc()
|
||||
|
||||
int rpc_join(char * sockname)
|
||||
{
|
||||
|
||||
FILE *f = fopen("/Users/Joseph/utest2/_log.txt","a");
|
||||
fprintf(f, sockname);
|
||||
|
||||
if(sockname == NULL) {
|
||||
printf("Warning, rpc netpath is NULL\n");
|
||||
}
|
||||
@@ -277,39 +276,65 @@ ssize_t sock_fd_write(int sock, int fd)
|
||||
*/
|
||||
ssize_t sock_fd_read(int sock, void *buf, ssize_t bufsize, int *fd)
|
||||
{
|
||||
FILE *file = fopen("/Users/Joseph/code/__log","a");
|
||||
|
||||
|
||||
ssize_t size;
|
||||
if (fd) {
|
||||
|
||||
fprintf(file, "A");
|
||||
|
||||
struct msghdr msg;
|
||||
struct iovec iov;
|
||||
union {
|
||||
struct cmsghdr cmsghdr;
|
||||
char control[CMSG_SPACE(sizeof (int))];
|
||||
} cmsgu;
|
||||
|
||||
fprintf(file, "B");
|
||||
|
||||
struct cmsghdr *cmsg;
|
||||
iov.iov_base = buf;
|
||||
iov.iov_len = bufsize;
|
||||
msg.msg_name = NULL;
|
||||
msg.msg_namelen = 0;
|
||||
|
||||
fprintf(file, "C");
|
||||
|
||||
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_control = cmsgu.control;
|
||||
msg.msg_controllen = sizeof(cmsgu.control);
|
||||
size = recvmsg (sock, &msg, 0);
|
||||
|
||||
fprintf(file, "D");
|
||||
|
||||
if (size < 0)
|
||||
return -1;
|
||||
cmsg = CMSG_FIRSTHDR(&msg);
|
||||
if (cmsg && cmsg->cmsg_len == CMSG_LEN(sizeof(int))) {
|
||||
fprintf(file, "E");
|
||||
|
||||
if (cmsg->cmsg_level != SOL_SOCKET) {
|
||||
fprintf(file, "F");
|
||||
|
||||
fprintf (stderr, "invalid cmsg_level %d\n",cmsg->cmsg_level);
|
||||
return -1;
|
||||
}
|
||||
if (cmsg->cmsg_type != SCM_RIGHTS) {
|
||||
fprintf(file, "G");
|
||||
|
||||
fprintf (stderr, "invalid cmsg_type %d\n",cmsg->cmsg_type);
|
||||
return -1;
|
||||
}
|
||||
*fd = *((int *) CMSG_DATA(cmsg));
|
||||
} else *fd = -1;
|
||||
} else {
|
||||
fprintf(file, "H");
|
||||
*fd = -1;}
|
||||
} else {
|
||||
fprintf(file, "I");
|
||||
|
||||
size = read (sock, buf, bufsize);
|
||||
if (size < 0) {
|
||||
fprintf(stderr, "sock_fd_read(): read: Error\n");
|
||||
|
||||
@@ -312,7 +312,14 @@ const char *get_netpath() {
|
||||
|
||||
ssize_t zt_recv(int fd, void *buf, int len)
|
||||
{
|
||||
return read(fd, buf, len);
|
||||
dwr("zt_recv(%d): \n", fd);
|
||||
|
||||
int bytes_read = read(fd, buf, len);
|
||||
if(bytes_read >= 0)
|
||||
{
|
||||
dwr("zt_recv(): MSG(%d): %s\n", bytes_read, buf);
|
||||
}
|
||||
return bytes_read;
|
||||
}
|
||||
|
||||
int zt_set_nonblock(int fd)
|
||||
@@ -470,11 +477,15 @@ const char *get_netpath() {
|
||||
|
||||
int zt_accept(ACCEPT_SIG)
|
||||
{
|
||||
//dwr(MSG_DEBUG,"zt_accept(%d):\n", sockfd);
|
||||
dwr(MSG_DEBUG,"zt_accept(%d):\n", sockfd);
|
||||
// FIXME: Find a better solution for this before production
|
||||
#if !defined(__UNITY_3D__)
|
||||
if(addr)
|
||||
addr->sa_family = AF_INET;
|
||||
|
||||
#endif
|
||||
int new_fd = get_new_fd(sockfd);
|
||||
dwr(MSG_DEBUG,"newfd = %d\n", new_fd);
|
||||
|
||||
if(new_fd > 0) {
|
||||
errno = ERR_OK;
|
||||
return new_fd;
|
||||
|
||||
Reference in New Issue
Block a user