77#include "rpc_common.h"
88#include "De_Serialization/serialize.h"
99
10- int
11- rpc_send_recv (ser_buff_t * client_send_ser_buffer ,
12- ser_buff_t * client_recv_ser_buffer ){
13-
14- struct sockaddr_in dest ;
15- int sockfd = 0 , rc = 0 , recv_size = 0 ;
16- int addr_len ;
17-
18- dest .sin_family = AF_INET ;
19- dest .sin_port = htons (SERVER_PORT );
20- struct hostent * host = (struct hostent * )gethostbyname (SERVER_IP );
21- dest .sin_addr = * ((struct in_addr * )host -> h_addr );
22- addr_len = sizeof (struct sockaddr );
23-
24- sockfd = socket (AF_INET , SOCK_DGRAM , IPPROTO_UDP );
25- if (sockfd == -1 ){
26- printf ("socket creation failed\n" );
27- return -1 ;
28- }
29-
30- rc = sendto (sockfd , client_send_ser_buffer -> b ,
31- get_serialize_buffer_length (client_send_ser_buffer ),
32- 0 , (struct sockaddr * )& dest , sizeof (struct sockaddr ));
33-
34- printf ("%s() : %d bytes sent\n" , __FUNCTION__ , rc );
35-
36- recv_size = recvfrom (sockfd , client_recv_ser_buffer -> b ,
37- get_serialize_buffer_length (client_recv_ser_buffer ), 0 ,
38- (struct sockaddr * )& dest , & addr_len );
39-
40- printf ("%s() : %d bytes recieved\n" , __FUNCTION__ , recv_size );
41-
42- return recv_size ;
10+ void
11+ rpc_send_recv (ser_buff_t * client_send_ser_buffer ,
12+ ser_buff_t * client_recv_ser_buffer ){
4313}
4414
15+
4516/* client_stub_marshal()*/
4617ser_buff_t *
4718multiply_client_stub_marshal (int a , int b ){
@@ -54,38 +25,21 @@ multiply_client_stub_marshal(int a, int b){
5425 /*Serialize the second Argument*/
5526 serialize_data (client_send_ser_buffer , (char * )& b , sizeof (int ));
5627
57- /*Serialize buffer looks like this
58- *
59- * +---------+---------+
60- * | | |
61- * | Arg1 | Arg2 |
62- * +---------+---------+
63- * <----4----><----4--->
28+ /*Serialize buffer looks like this
29+ *
30+ * +---------+---------+
31+ * | | |
32+ * | Arg1 | Arg2 |
33+ * +---------+---------+
34+ * <----4----><----4--->
6435 * */
6536 return client_send_ser_buffer ;
6637}
6738
68- int multiply_client_stub_unmarshal (ser_buff_t * client_recv_ser_buffer ){
69-
70- /*Reconstruct the result obtained from Server*/
71- int res = 0 ;
72- de_serialize_data ((char * )& res , client_recv_ser_buffer , sizeof (int ));
73- return res ;
74- }
75-
76- void
77- init_rpc_infra (){
78-
79- /*Initialize anything before starting RPC , if any*/
80- }
81-
8239
8340int
8441multiply_rpc (int a , int b ){
8542
86- /*init RPC buffers*/
87- init_rpc_infra ();
88-
8943 /*Step 2 : Serialize/Marshal the arguments*/
9044 /*Signature : ser_buff_t* (client_stub_marshal) <Arg1, Arg2, . . . ,> */
9145 ser_buff_t * client_send_ser_buffer = multiply_client_stub_marshal (a , b );
@@ -108,19 +62,6 @@ multiply_rpc(int a , int b){
10862 client_send_ser_buffer = NULL ;
10963
11064 /*Step 4 , 5, 6 , 7, 8 are executed on Server side*/
111-
112- /*Step 9 : Unmarshal the serialized data (result) recvd from Server,
113- * and reconsctruct the RPC return type
114- * Signature : <rpc return type> (client_stub_unmarshal) <ser_buff_t *>
115- * */
116-
117- int res = multiply_client_stub_unmarshal (client_recv_ser_buffer );
118-
119- /*Client has successfully reconstructed the result object from
120- * serialized data recvd from Server, Time to free client_recv_ser_buffer*/
121-
122- free_serialize_buffer (client_recv_ser_buffer );
123- return res ;
12465}
12566
12667int
0 commit comments