/* Guochun Shi: gshi@ncsa.uiuc.edu */ #include #include #include #include #include #include #include #include "msg.h" static const char* sockfile = SOCKFILE; static int sockfd = -1; static void set_socket_file(const char* s_fname) { sockfile = s_fname; return; } int vf_client_init(void) { int rc; struct sockaddr_un sa; const char* filename = sockfile; memset(&sa, 0, sizeof(sa)); sa.sun_family = AF_LOCAL; strncpy (sa.sun_path, filename, sizeof (sa.sun_path)); sockfd = socket(AF_LOCAL, SOCK_STREAM, 0); if (sockfd < 0) { perror("socket: allocation failed"); return -1; } rc = connect(sockfd, (struct sockaddr*)&sa, sizeof(sa)); if (rc) { perror("connect"); return -1; } return 0; } int vf_client_send(int i, int j, char* ptr, int size) { vf_msg_head_t msghead; int rc; msghead.size = size; msghead.i = i; msghead.j = j; rc = send(sockfd, &msghead, sizeof(msghead), 0); if (rc < 0){ perror("send"); return -1; } rc = send(sockfd, ptr, size, 0); if (rc < 0){ perror("send"); return -1; } return 0; } int vf_client_sync(void) { int rc; int result; rc = recv(sockfd, &result, sizeof(result), 0); if (rc <= 0){ perror("recv"); return -1; } if (result != ITER_SYNC){ printf("sync error\n"); return -1; } return 0; }