Skip to content

Commit 887759c

Browse files
committed
Update ASIO wrapper constructors to only take BoostEnvironment and VMIdentifier
* Restore the behavior of creating a new TCPConnection in every call of startAsyncAccept().
1 parent 76914ec commit 887759c

File tree

7 files changed

+34
-29
lines changed

7 files changed

+34
-29
lines changed

vm/boostenv/main/boostenvpipe-decl.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class PipeConnection: public BaseSocketConnection<PipeConnection,
4141
boost::asio::local::stream_protocol> {
4242
public:
4343
inline
44-
PipeConnection(VM vm);
44+
PipeConnection(BoostEnvironment& env, VMIdentifier vm);
4545
};
4646

4747
#endif // BOOST_ASIO_HAS_LOCAL_SOCKETS

vm/boostenv/main/boostenvpipe.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ namespace mozart { namespace boostenv {
3939
// PipeConnection //
4040
////////////////////
4141

42-
PipeConnection::PipeConnection(VM vm):
43-
BaseSocketConnection(vm) {
42+
PipeConnection::PipeConnection(BoostEnvironment& env, VMIdentifier vm):
43+
BaseSocketConnection(env, vm) {
4444
}
4545

4646
#endif // BOOST_ASIO_HAS_LOCAL_SOCKETS

vm/boostenv/main/boostenvtcp-decl.hh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TCPConnection: public BaseSocketConnection<TCPConnection,
3939
boost::asio::ip::tcp> {
4040
public:
4141
inline
42-
TCPConnection(VM vm);
42+
TCPConnection(BoostEnvironment& env, VMIdentifier vm);
4343

4444
public:
4545
inline
@@ -61,9 +61,9 @@ private:
6161
public:
6262
typedef std::shared_ptr<TCPAcceptor> pointer;
6363

64-
static pointer create(VM vm, const tcp::endpoint& endpoint) {
64+
static pointer create(BoostEnvironment& env, VMIdentifier vm, const tcp::endpoint& endpoint) {
6565
// Cannot use make_shared as constructor is private
66-
return pointer(new TCPAcceptor(vm, endpoint));
66+
return pointer(new TCPAcceptor(env, vm, endpoint));
6767
}
6868

6969
public:
@@ -72,8 +72,7 @@ public:
7272
}
7373

7474
inline
75-
void startAsyncAccept(TCPConnection::pointer connection,
76-
const ProtectedNode& connectionNode);
75+
void startAsyncAccept(const ProtectedNode& connectionNode);
7776

7877
inline
7978
boost::system::error_code cancel();
@@ -83,7 +82,7 @@ public:
8382

8483
private:
8584
inline
86-
TCPAcceptor(VM vm, const tcp::endpoint& endpoint);
85+
TCPAcceptor(BoostEnvironment& env, VMIdentifier vm, const tcp::endpoint& endpoint);
8786

8887
private:
8988
BoostEnvironment& env;

vm/boostenv/main/boostenvtcp.hh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ namespace mozart { namespace boostenv {
3737
// TCPConnection //
3838
///////////////////
3939

40-
TCPConnection::TCPConnection(VM vm):
41-
BaseSocketConnection(vm), _resolver(env.io_service) {
40+
TCPConnection::TCPConnection(BoostEnvironment& env, VMIdentifier vm):
41+
BaseSocketConnection(env, vm), _resolver(env.io_service) {
4242
}
4343

4444
void TCPConnection::startAsyncConnect(std::string host, std::string service,
@@ -80,15 +80,14 @@ void TCPConnection::startAsyncConnect(std::string host, std::string service,
8080
// TCPAcceptor //
8181
/////////////////
8282

83-
TCPAcceptor::TCPAcceptor(VM vm,
83+
TCPAcceptor::TCPAcceptor(BoostEnvironment& env, VMIdentifier vm,
8484
const tcp::endpoint& endpoint):
85-
env(BoostEnvironment::forVM(vm)),
86-
vm(BoostVM::forVM(vm).identifier),
87-
_acceptor(env.io_service, endpoint) {
85+
env(env), vm(vm), _acceptor(env.io_service, endpoint) {
8886
}
8987

90-
void TCPAcceptor::startAsyncAccept(TCPConnection::pointer connection,
91-
const ProtectedNode& connectionNode) {
88+
void TCPAcceptor::startAsyncAccept(const ProtectedNode& connectionNode) {
89+
TCPConnection::pointer connection = TCPConnection::create(env, vm);
90+
9291
auto handler = [=] (const boost::system::error_code& error) {
9392
if (!error) {
9493
env.postVMEvent(vm, [=] (BoostVM& boostVM) {
@@ -101,7 +100,7 @@ void TCPAcceptor::startAsyncAccept(TCPConnection::pointer connection,
101100
});
102101
} else {
103102
// Try again
104-
startAsyncAccept(connection, connectionNode);
103+
startAsyncAccept(connectionNode);
105104
}
106105
};
107106

vm/boostenv/main/boostenvutils-decl.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ public:
4949
public:
5050
typedef std::shared_ptr<T> pointer;
5151

52-
static pointer create(VM vm) {
53-
return std::make_shared<T>(vm);
52+
static pointer create(BoostEnvironment& env, VMIdentifier vm) {
53+
return std::make_shared<T>(env, vm);
5454
}
5555

5656
public:
5757
inline
58-
BaseSocketConnection(VM vm);
58+
BaseSocketConnection(BoostEnvironment& env, VMIdentifier vm);
5959

6060
public:
6161
typename protocol::socket& socket() {

vm/boostenv/main/boostenvutils.hh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ namespace mozart { namespace boostenv {
3838
//////////////////////////
3939

4040
template <typename T, typename P>
41-
BaseSocketConnection<T, P>::BaseSocketConnection(VM vm):
42-
env(BoostEnvironment::forVM(vm)),
43-
vm(BoostVM::forVM(vm).identifier),
44-
_socket(env.io_service) {
41+
BaseSocketConnection<T, P>::BaseSocketConnection(BoostEnvironment& env, VMIdentifier vm):
42+
env(env), vm(vm), _socket(env.io_service) {
4543
}
4644

4745
template <typename T, typename P>

vm/boostenv/main/modos.hh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ using namespace ::mozart::builtins;
5959
class ModOS: public Module {
6060
private:
6161
static const size_t MaxBufferSize = 1024*1024;
62+
63+
static BoostEnvironment& env(VM vm) {
64+
return BoostEnvironment::forVM(vm);
65+
}
66+
67+
static VMIdentifier ident(VM vm) {
68+
return BoostVM::forVM(vm).identifier;
69+
}
70+
6271
public:
6372
ModOS(): Module("OS") {}
6473

@@ -483,7 +492,7 @@ public:
483492
endpoint = tcp::endpoint(tcp::v6(), intPort);
484493

485494
try {
486-
auto acceptor = TCPAcceptor::create(vm, endpoint);
495+
auto acceptor = TCPAcceptor::create(env(vm), ident(vm), endpoint);
487496
result = build(vm, acceptor);
488497
} catch (const boost::system::system_error& error) {
489498
raiseOSError(vm, "tcpAcceptorCreate", error);
@@ -501,7 +510,7 @@ public:
501510
auto connectionNode =
502511
BoostVM::forVM(vm).createAsyncIOFeedbackNode(result);
503512

504-
tcpAcceptor->startAsyncAccept(TCPConnection::create(vm), connectionNode);
513+
tcpAcceptor->startAsyncAccept(connectionNode);
505514
}
506515
};
507516

@@ -544,7 +553,7 @@ public:
544553
ozVSGet(vm, host, hostBufSize, strHost);
545554
ozVSGet(vm, service, serviceBufSize, strService);
546555

547-
auto tcpConnection = TCPConnection::create(vm);
556+
auto tcpConnection = TCPConnection::create(env(vm), ident(vm));
548557

549558
auto statusNode =
550559
BoostVM::forVM(vm).createAsyncIOFeedbackNode(status);
@@ -1004,7 +1013,7 @@ public:
10041013

10051014
#else /* !MOZART_WINDOWS */
10061015

1007-
auto pipeConnection = PipeConnection::create(vm);
1016+
auto pipeConnection = PipeConnection::create(env(vm), ident(vm));
10081017

10091018
// Build the Oz value now so that it is registered for GC
10101019
auto ozPipe = build(vm, pipeConnection);

0 commit comments

Comments
 (0)