XINU
Functions
rfscomm.c File Reference
#include <xinu.h>
Include dependency graph for rfscomm.c:

Go to the source code of this file.

Functions

int32 rfscomm (struct rf_msg_hdr *msg, int32 mlen, struct rf_msg_hdr *reply, int32 rlen)
 

Function Documentation

◆ rfscomm()

int32 rfscomm ( struct rf_msg_hdr msg,
int32  mlen,
struct rf_msg_hdr reply,
int32  rlen 
)

Definition at line 10 of file rfscomm.c.

References htonl, kprintf(), ntohl, ntohs, Rf_data, rfdata::rf_loc_port, RF_MSG_RESPONSE, rfdata::rf_registered, RF_RETRIES, rfdata::rf_seq, rfdata::rf_ser_ip, rfdata::rf_ser_port, RF_TIMEOUT, rfdata::rf_udp_slot, SYSERR, TIMEOUT, TRUE, udp_recv(), udp_register(), and udp_send().

Referenced by rflread(), rflwrite(), rfscontrol(), rfsndmsg(), and rfsopen().

16 {
17  int32 i; /* Counts retries */
18  int32 retval; /* Return value */
19  int32 seq; /* Sequence for this exchange */
20  int16 rtype; /* Reply type in host byte order*/
21  int32 slot; /* UDP slot */
22 
23  /* For the first time after reboot, register the server port */
24 
25  if ( ! Rf_data.rf_registered ) {
26  if ( (slot = udp_register(Rf_data.rf_ser_ip,
28  Rf_data.rf_loc_port)) == SYSERR) {
29  return SYSERR;
30  }
31  Rf_data.rf_udp_slot = slot;
33  }
34 
35  /* Assign message next sequence number */
36 
37  seq = Rf_data.rf_seq++;
38  msg->rf_seq = htonl(seq);
39 
40  /* Repeat RF_RETRIES times: send message and receive reply */
41 
42  for (i=0; i<RF_RETRIES; i++) {
43 
44  /* Send a copy of the message */
45 
46  retval = udp_send(Rf_data.rf_udp_slot, (char *)msg,
47  mlen);
48  if (retval == SYSERR) {
49  kprintf("Cannot send to remote file server\n");
50  return SYSERR;
51  }
52 
53  /* Receive a reply */
54 
55  retval = udp_recv(Rf_data.rf_udp_slot, (char *)reply,
56  rlen, RF_TIMEOUT);
57 
58  if (retval == TIMEOUT) {
59  continue;
60  } else if (retval == SYSERR) {
61  kprintf("Error reading remote file reply\n");
62  return SYSERR;
63  }
64 
65  /* Verify that sequence in reply matches request */
66 
67  if (ntohl(reply->rf_seq) != seq) {
68  continue;
69  }
70 
71  /* Verify the type in the reply matches the request */
72 
73  rtype = ntohs(reply->rf_type);
74  if (rtype != ( ntohs(msg->rf_type) | RF_MSG_RESPONSE) ) {
75  continue;
76  }
77 
78  return retval; /* Return length to caller */
79  }
80 
81  /* Retries exhausted without success */
82 
83  kprintf("Timeout on exchange with remote file server\n");
84  return TIMEOUT;
85 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
int32 rf_seq
Definition: rfilesys.h:33
int32 udp_recv(uid32, char *, int32, uint32)
Definition: udp.c:146
status udp_send(uid32, char *, int32)
Definition: udp.c:316
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
uint16 rf_ser_port
Definition: rfilesys.h:35
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
bool8 rf_registered
Definition: rfilesys.h:39
#define ntohl(x)
Definition: prototypes.h:623
struct rfdata Rf_data
Definition: rfsinit.c:10
#define RF_MSG_RESPONSE
Definition: rfilesys.h:81
int32 rf_udp_slot
Definition: rfilesys.h:37
#define RF_TIMEOUT
Definition: rfilesys.h:63
#define TRUE
Boolean True(1)
Definition: kernel.h:65
short int16
符号あり16ビット整数(short)
Definition: kernel.h:13
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uid32 udp_register(uint32, uint16, uint16)
Definition: udp.c:85
#define ntohs(x)
Definition: prototypes.h:622
uint32 rf_ser_ip
Definition: rfilesys.h:34
uint16 rf_loc_port
Definition: rfilesys.h:36
#define htonl(x)
Definition: prototypes.h:620
#define RF_RETRIES
Definition: rfilesys.h:62
Here is the call graph for this function:
Here is the caller graph for this function: