summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/socket/netstack/netstack_state.go
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@google.com>2021-10-07 14:02:20 -0700
committergVisor bot <gvisor-bot@google.com>2021-10-07 14:04:55 -0700
commita7045f051f7bcdca079cdb0636f728a18b609121 (patch)
tree31150f22f45853b4b3be2e782a32a32e5017a012 /pkg/sentry/socket/netstack/netstack_state.go
parentd93c3c2eff5e4c92d7740d82ff079a0ae51f60d9 (diff)
Store timestamps as time.Time
Rather than boiling down to an integer eagerly, do it as late as possible. PiperOrigin-RevId: 401599308
Diffstat (limited to 'pkg/sentry/socket/netstack/netstack_state.go')
-rw-r--r--pkg/sentry/socket/netstack/netstack_state.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/sentry/socket/netstack/netstack_state.go b/pkg/sentry/socket/netstack/netstack_state.go
new file mode 100644
index 000000000..591e00d42
--- /dev/null
+++ b/pkg/sentry/socket/netstack/netstack_state.go
@@ -0,0 +1,31 @@
+// Copyright 2021 The gVisor Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package netstack
+
+import (
+ "time"
+)
+
+func (s *socketOpsCommon) saveTimestamp() int64 {
+ s.readMu.Lock()
+ defer s.readMu.Unlock()
+ return s.timestamp.UnixNano()
+}
+
+func (s *socketOpsCommon) loadTimestamp(nsec int64) {
+ s.readMu.Lock()
+ defer s.readMu.Unlock()
+ s.timestamp = time.Unix(0, nsec)
+}