Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

sclang: init Windows sockets before use and cleanup after

  • Loading branch information...
commit eb064e119add376cce13237fdbb62f08fa8971a0 1 parent d92e2e7
@jleben jleben authored
View
1  include/lang/SCBase.h
@@ -49,6 +49,7 @@ void pprintf(unsigned char *str, char *fmt, ...);
SC_DLLEXPORT_C void schedInit();
SC_DLLEXPORT_C void init_OSC(int port);
+SC_DLLEXPORT_C void cleanup_OSC();
SC_DLLEXPORT_C bool pyr_init_mem_pools(int runtime_space, int runtime_grow);
SC_DLLEXPORT_C void schedRun();
View
1  include/lang/SC_LanguageClient.h
@@ -72,6 +72,7 @@ class SC_DLLEXPORT SC_LanguageClient
// initialize language runtime
void initRuntime(const Options& opt=Options());
+ void shutdownRuntime();
// return application name
const char* getName() const { return mName; }
View
26 lang/LangPrimSource/OSCData.cpp
@@ -775,6 +775,15 @@ void init_OSC(int port);
void init_OSC(int port)
{
postfl("init_OSC\n");
+
+#ifdef _WIN32
+ WSAData wsaData;
+ int nCode;
+ if ((nCode = WSAStartup(MAKEWORD(1, 1), &wsaData)) != 0) {
+ error( "sclang: init_OSC: WSAStartup() failed with error code %d.\n", nCode );
+ }
+#endif
+
try {
gUDPport = new SC_UdpInPort(port);
} catch (...) {
@@ -782,6 +791,14 @@ void init_OSC(int port)
}
}
+void cleanup_OSC()
+{
+ postfl( "cleaning up OSC\n");
+#ifdef _WIN32
+ WSACleanup();
+#endif
+}
+
int prGetHostByName(VMGlobals *g, int numArgsPushed);
int prGetHostByName(VMGlobals *g, int numArgsPushed)
{
@@ -792,7 +809,14 @@ int prGetHostByName(VMGlobals *g, int numArgsPushed)
if (err) return err;
struct hostent *he = gethostbyname(hostname);
- if (!he) return errFailed;
+ if (!he) {
+#ifdef _WIN32
+ int err = WSAGetLastError();
+ error("gethostbyname(\"%s\") failed with error code %i.\n",
+ hostname, err);
+#endif
+ return errFailed;
+ }
SetInt(a, ntohl(*(int*)he->h_addr));
View
5 lang/LangSource/SC_LanguageClient.cpp
@@ -103,6 +103,11 @@ void SC_LanguageClient::initRuntime(const Options& opt)
}
}
+void SC_LanguageClient::shutdownRuntime()
+{
+ cleanup_OSC();
+}
+
bool SC_LanguageClient::readLibraryConfig(const char* filePath, const char* fileName)
{
SC_LibraryConfigFile file(&::post);
View
2  lang/LangSource/SC_TerminalClient.cpp
@@ -259,6 +259,8 @@ int SC_TerminalClient::run(int argc, char** argv)
shutdownLibrary();
flush();
+ shutdownRuntime();
+
return mReturnCode;
}
View
2  lang/LangSource/cmdLineFuncs.cpp
@@ -181,6 +181,8 @@ int main()
compileLibrary();
runLibrary(s_run); fflush(postfile);
+ cleanup_OSC();
+
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.