-
Notifications
You must be signed in to change notification settings - Fork 0
/
envelope_net.cpp
109 lines (84 loc) · 3.55 KB
/
envelope_net.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
Advanced Computing Center for Research and Education Proprietary License
Version 1.0 (April 2006)
Copyright (c) 2006, Advanced Computing Center for Research and Education,
Vanderbilt University, All rights reserved.
This Work is the sole and exclusive property of the Advanced Computing Center
for Research and Education department at Vanderbilt University. No right to
disclose or otherwise disseminate any of the information contained herein is
granted by virtue of your possession of this software except in accordance with
the terms and conditions of a separate License Agreement entered into with
Vanderbilt University.
THE AUTHOR OR COPYRIGHT HOLDERS PROVIDES THE "WORK" ON AN "AS IS" BASIS,
WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, TITLE, FITNESS FOR A PARTICULAR
PURPOSE, AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Vanderbilt University
Advanced Computing Center for Research and Education
230 Appleton Place
Nashville, TN 37203
http://www.accre.vanderbilt.edu
*/
#include "envelope.h"
#include "network.h"
#include "log.h"
//*********************************************************************
// envelope_send - Sends an envelope
//*********************************************************************
int envelope_send(NetStream_t *ns, envelope_t *env)
{
char buffer[ENVELOPE_SIZE];
int err;
envelope_encode(env, (unsigned char *)buffer);
err = write_netstream_block(ns, time(NULL)+30, buffer, ENVELOPE_SIZE);
if (err != NS_OK) {
log_printf(0, "envelope_send: write_netstream_block failed sending envelope header! err=%d ns=%d\n",err, ns_getid(ns));
}
return(err);
}
//*********************************************************************
// envelope_recv - Receives an envelope over the wire
//*********************************************************************
int envelope_recv(NetStream_t *ns, envelope_t *env)
{
char buffer[ENVELOPE_SIZE];
int err;
err = read_netstream_block(ns, time(NULL)+30, buffer, ENVELOPE_SIZE);
if (err != NS_OK) {
log_printf(0, "envelope_recv: read_netstream_block failed reading envelope header! err=%d ns=%d\n",err, ns_getid(ns));
}
return(envelope_parse(env, (unsigned char *)buffer));
}
//*********************************************************************
// envelope_simple_send - Sends a envelope with size 0 with only the cmd set
//*********************************************************************
int envelope_simple_send(NetStream_t *ns, uint32_t cmd)
{
envelope_t env;
env_command_t ecmd;
set_env_command_uint32(&ecmd, cmd);
envelope_set(&env, ecmd, 0);
return(envelope_send(ns, &env));
}
//*********************************************************************
// envelope_simple_recv - Receives an empty envelope and reports the cmd
//*********************************************************************
int envelope_simple_recv(NetStream_t *ns, uint32_t *cmd)
{
envelope_t env;
env_command_t ecmd;
int err;
uint32_t size;
err = envelope_recv(ns, &env);
if (err != 0) return(err);
envelope_get(&env, &ecmd, &size);
err = size;
log_printf(15, "envelope_simple_recv: cmd=%hhu %hhu %hhu %hhu size=%d\n",
ecmd.byte[0], ecmd.byte[1], ecmd.byte[2], ecmd.byte[3], err);
if (size != 0) return(size);
*cmd = get_env_command_uint32(&ecmd);
return(0);
}