1 /*
2
3 This file is part of the Maude 2 interpreter.
4
5 Copyright 1997-2003 SRI International, Menlo Park, CA 94025, USA.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20
21 */
22
23 void
errorReply(const char * errorMessage,FreeDagNode * originalMessage,ObjectSystemRewritingContext & context)24 SocketManagerSymbol::errorReply(const char* errorMessage,
25 FreeDagNode* originalMessage,
26 ObjectSystemRewritingContext& context)
27 {
28 Vector<DagNode*> reply(3);
29 reply[1] = originalMessage->getArgument(0);
30 reply[2] = new StringDagNode(stringSymbol, errorMessage);
31 DagNode* target = originalMessage->getArgument(1);
32 reply[0] = target;
33 context.bufferMessage(target, socketErrorMsg->makeDagNode(reply));
34 }
35
36
37 void
createdSocketReply(int fd,FreeDagNode * originalMessage,ObjectSystemRewritingContext & context)38 SocketManagerSymbol::createdSocketReply(int fd,
39 FreeDagNode* originalMessage,
40 ObjectSystemRewritingContext& context)
41 {
42 //activeSockets[fd].state = NOMINAL;
43 Vector<DagNode*> reply(1, 3);
44 reply[0] = succSymbol->makeNatDag(fd);
45 DagNode* socketName = socketOidSymbol->makeDagNode(reply);
46 context.addExternalObject(socketName, this);
47 reply.resize(3);
48 reply[2] = socketName;
49 reply[1] = originalMessage->getArgument(0);
50 DagNode* target = originalMessage->getArgument(1);
51 reply[0] = target;
52 context.bufferMessage(target, createdSocketMsg->makeDagNode(reply));
53 }
54
55 void
acceptedClientReply(const char * addr,int fd,FreeDagNode * originalMessage,ObjectSystemRewritingContext & context)56 SocketManagerSymbol::acceptedClientReply(const char* addr,
57 int fd,
58 FreeDagNode* originalMessage,
59 ObjectSystemRewritingContext& context)
60 {
61 //activeSockets[fd].state = NOMINAL;
62 Vector<DagNode*> reply(1, 4);
63 reply[0] = succSymbol->makeNatDag(fd);
64 DagNode* socketName = socketOidSymbol->makeDagNode(reply);
65 context.addExternalObject(socketName, this);
66 reply.resize(4);
67 reply[3] = socketName;
68 reply[2] = new StringDagNode(stringSymbol, addr);
69 reply[1] = originalMessage->getArgument(0);
70 DagNode* target = originalMessage->getArgument(1);
71 reply[0] = target;
72 context.bufferMessage(target, acceptedClientMsg->makeDagNode(reply));
73
74 }
75
76 void
sentMsgReply(FreeDagNode * originalMessage,ObjectSystemRewritingContext & context)77 SocketManagerSymbol::sentMsgReply(FreeDagNode* originalMessage,
78 ObjectSystemRewritingContext& context)
79 {
80 Vector<DagNode*> reply(2);
81 DagNode* target = originalMessage->getArgument(1);
82 reply[0] = target;
83 reply[1] = originalMessage->getArgument(0);
84 context.bufferMessage(target, sentMsg->makeDagNode(reply));
85 }
86
87 void
receivedMsgReply(char buffer[],ssize_t length,FreeDagNode * originalMessage,ObjectSystemRewritingContext & context)88 SocketManagerSymbol::receivedMsgReply(char buffer[],
89 ssize_t length,
90 FreeDagNode* originalMessage,
91 ObjectSystemRewritingContext& context)
92 {
93 Rope text(buffer, length);
94 Vector<DagNode*> reply(3);
95 reply[1] = originalMessage->getArgument(0);
96 reply[2] = new StringDagNode(stringSymbol, text);
97 DagNode* target = originalMessage->getArgument(1);
98 reply[0] = target;
99 context.bufferMessage(target, receivedMsg->makeDagNode(reply));
100 }
101
102 void
closedSocketReply(int socketId,const char * errorMessage,FreeDagNode * originalMessage,ObjectSystemRewritingContext & context)103 SocketManagerSymbol::closedSocketReply(int socketId,
104 const char* errorMessage,
105 FreeDagNode* originalMessage,
106 ObjectSystemRewritingContext& context)
107 {
108 close(socketId);
109 DagNode* socketName = originalMessage->getArgument(0);
110 context.deleteExternalObject(socketName);
111 activeSockets.erase(socketId);
112 Vector<DagNode*> reply(3);
113 reply[1] = socketName;
114 reply[2] = new StringDagNode(stringSymbol, errorMessage);
115 DagNode* target = originalMessage->getArgument(1);
116 reply[0] = target;
117 context.bufferMessage(target, closedSocketMsg->makeDagNode(reply));
118 }
119