@@ -114,6 +114,12 @@ static void segfault(int sig, siginfo_t *info, void *unused) {
114114 raise (SIGSEGV);
115115}
116116
117+ conn_t * stored_conn;
118+
119+ void store_conn (const void *conn) {
120+ stored_conn = (conn_t *)conn;
121+ }
122+
117123typedef struct callBackData {
118124 conn_t *conn;
119125 void (*callback)(void *);
@@ -122,15 +128,53 @@ typedef struct callBackData {
122128
123129void invoke_host_func (void *data) {
124130 callBackData_t *tmp = (callBackData_t *)(data);
125- void *res;
131+ void * scuda_intercept_result;
132+
133+ // Validate connection
134+ if (!stored_conn) {
135+ std::cerr << " Error: Connection is NULL in invoke_host_func" << std::endl;
136+ return ;
137+ }
138+
139+ printf (" Invoking host function %p\n " , tmp->callback );
140+
141+ if (rpc_write_start_request (stored_conn, 1 ) < 0 ) {
142+ std::cerr << " Error: rpc_write_start_request failed" << std::endl;
143+ return ;
144+ }
145+ if (rpc_write (stored_conn, &tmp->callback , sizeof (void *)) < 0 ) {
146+ std::cerr << " Error: rpc_write failed on callback" << std::endl;
147+ return ;
148+ }
149+ if (rpc_write (stored_conn, &tmp->data , sizeof (void *)) < 0 ) {
150+ std::cerr << " Error: rpc_write failed on data" << std::endl;
151+ return ;
152+ }
126153
127- printf (" invoking host function %p\n " , tmp->callback );
154+ // Ensure request is fully sent before waiting for response
155+ if (rpc_write_end (stored_conn) < 0 ) {
156+ std::cerr << " Error: rpc_write_end failed" << std::endl;
157+ return ;
158+ }
159+
160+ printf (" hereeee %p\n " , tmp->callback );
161+
162+ if (rpc_wait_for_response (stored_conn) < 0 ) {
163+ std::cerr << " Error: rpc_wait_for_response failed" << std::endl;
164+ return ;
165+ }
166+
167+ if (rpc_read (stored_conn, &scuda_intercept_result, sizeof (void *)) < 0 ) {
168+ std::cerr << " Error: rpc_read failed on scuda_intercept_result" << std::endl;
169+ return ;
170+ }
171+
172+ if (rpc_read_end (stored_conn) < 0 ) {
173+ std::cerr << " Error: rpc_read_end failed" << std::endl;
174+ return ;
175+ }
128176
129- if (rpc_write_start_request (tmp->conn , 1 ) < 0 ||
130- rpc_write (tmp->conn , &tmp->callback , sizeof (void *)) < 0 ||
131- rpc_write (tmp->conn , &tmp->data , sizeof (void *)) < 0 ||
132- rpc_wait_for_response (tmp->conn ) < 0 || rpc_read_end (tmp->conn ) < 0 )
133- std::cout << " failed to write memory: " << &faulting_address << std::endl;
177+ std::cout << " RESULT IS: " << scuda_intercept_result << std::endl;
134178}
135179
136180void append_host_func_ptr (const void *conn, void *ptr) {
@@ -172,7 +216,9 @@ void client_handler(int connfd) {
172216 printf (" Client connected.\n " );
173217
174218 while (1 ) {
175- unsigned int op = rpc_dispatch (&conn, 0 );
219+ int op = rpc_dispatch (&conn, 0 );
220+
221+ std::cout << " GOT OP: " << op << std::endl;
176222
177223 auto opHandler = get_handler (op);
178224 if (opHandler (&conn) < 0 ) {
@@ -183,6 +229,7 @@ void client_handler(int connfd) {
183229 if (pthread_mutex_destroy (&conn.read_mutex ) < 0 ||
184230 pthread_mutex_destroy (&conn.write_mutex ) < 0 )
185231 std::cerr << " Error destroying mutex." << std::endl;
232+
186233 close (connfd);
187234}
188235
0 commit comments