diff options
author | Mikhail Kurinnoi <m.kurinnoi@samsung.com> | 2019-02-05 13:58:54 +0300 |
---|---|---|
committer | Alexander Soldatov/AI Ecosystem Lab /SRR/Staff Engineer/삼성전자 <soldatov.a@samsung.com> | 2019-02-05 18:01:03 +0300 |
commit | 6cdf0c4611de3a44cd2a49049924ee80687ee96b (patch) | |
tree | 27cbf79552b3383101ac312e8ab52833a0d06e5d | |
parent | f809754e6dd8364b4d2d72cc0ff91e3c912aed68 (diff) | |
download | heaptrack-6cdf0c4611de3a44cd2a49049924ee80687ee96b.tar.gz heaptrack-6cdf0c4611de3a44cd2a49049924ee80687ee96b.tar.bz2 heaptrack-6cdf0c4611de3a44cd2a49049924ee80687ee96b.zip |
Add TCP socket prompt feature.
Provide custom socket prompt string in order to check
send/receive capability of established connection.
Required by VS plugin.
-rw-r--r-- | src/track/libheaptrack.cpp | 16 | ||||
-rw-r--r-- | src/track/outstream/outstream.h | 1 | ||||
-rw-r--r-- | src/track/outstream/outstream_file.cpp | 9 | ||||
-rw-r--r-- | src/track/outstream/outstream_file.h | 1 | ||||
-rw-r--r-- | src/track/outstream/outstream_socket.cpp | 9 | ||||
-rw-r--r-- | src/track/outstream/outstream_socket.h | 1 |
6 files changed, 35 insertions, 2 deletions
diff --git a/src/track/libheaptrack.cpp b/src/track/libheaptrack.cpp index f93acfb..03cd85c 100644 --- a/src/track/libheaptrack.cpp +++ b/src/track/libheaptrack.cpp @@ -164,8 +164,20 @@ outStream* createFile(const char* fileName) } unsetenv("DUMP_HEAPTRACK_SOCKET"); } - debugLog<VerboseOutput>("%s", "will write to socket"); - return OpenStream<outStreamSOCKET, uint16_t>(Port); + + outStream *tmpStream = OpenStream<outStreamSOCKET, uint16_t>(Port); + + env = getenv("DUMP_HEAPTRACK_SOCKET_PROMPT"); + if (env) { + if (fprintf(tmpStream, "%s\n", env) < 0 + || !tmpStream->Flush()) { + fprintf(stderr, "WARNING: can't send socket prompt \"%s\".\n", env); + } + unsetenv("DUMP_HEAPTRACK_SOCKET_PROMPT"); + } + + debugLog<VerboseOutput>("will write to socket/%p\n", tmpStream); + return tmpStream; } if (outputFileName.empty()) { diff --git a/src/track/outstream/outstream.h b/src/track/outstream/outstream.h index 0d3084d..e927af4 100644 --- a/src/track/outstream/outstream.h +++ b/src/track/outstream/outstream.h @@ -18,6 +18,7 @@ public: virtual int Putc(int Char) noexcept = 0; virtual int Puts(const char *String) noexcept = 0; + virtual bool Flush() noexcept = 0; }; template <class Implementation, class Initialization> diff --git a/src/track/outstream/outstream_file.cpp b/src/track/outstream/outstream_file.cpp index 54ab758..855b979 100644 --- a/src/track/outstream/outstream_file.cpp +++ b/src/track/outstream/outstream_file.cpp @@ -58,3 +58,12 @@ int outStreamFILE::Puts(const char *String) noexcept }
return fputs(String, Stream_);
}
+
+bool outStreamFILE::Flush() noexcept
+{
+ if (!Stream_) {
+ errno = EIO;
+ return false;
+ }
+ return fflush(Stream_) != EOF;
+}
diff --git a/src/track/outstream/outstream_file.h b/src/track/outstream/outstream_file.h index b4167d2..0b0d9f9 100644 --- a/src/track/outstream/outstream_file.h +++ b/src/track/outstream/outstream_file.h @@ -31,6 +31,7 @@ public: int Putc(int Char) noexcept override; int Puts(const char *String) noexcept override; + bool Flush() noexcept override; private: FILE *Stream_; diff --git a/src/track/outstream/outstream_socket.cpp b/src/track/outstream/outstream_socket.cpp index 2311cbe..65cd252 100644 --- a/src/track/outstream/outstream_socket.cpp +++ b/src/track/outstream/outstream_socket.cpp @@ -163,3 +163,12 @@ int outStreamSOCKET::Puts(const char *String) noexcept return EOF;
}
+
+bool outStreamSOCKET::Flush() noexcept
+{
+ if (Socket_ == -1) {
+ errno = EIO;
+ return false;
+ }
+ return FlushBuffer();
+}
diff --git a/src/track/outstream/outstream_socket.h b/src/track/outstream/outstream_socket.h index c02de54..910ca03 100644 --- a/src/track/outstream/outstream_socket.h +++ b/src/track/outstream/outstream_socket.h @@ -34,6 +34,7 @@ public: int Putc(int Char) noexcept override; int Puts(const char *String) noexcept override; + bool Flush() noexcept override; static constexpr int MinAllowedSocketPort = 1; static constexpr int MaxAllowedSocketPort = 65535; |