Jump to content

TCPStartUp() in a UDF - best practice?


orbs
 Share

Recommended Posts

as i understand, TCPStartUp() works for the entire process, and is scope-agnostic. suppose i'm writing a UDF that makes use of TCP. i neither know nor care if the calling script uses TCP too. the calling script may or may not call TCPStartUp() or TCPShutDown() at its discretion. should i be concerned about that at all?

my initial thought was to mandatory call TCPStartUp() in my UDF, and register an OnExit function for TCPShutDown(). but what if the calling script does the same? what if the calling script calls TCPShutDown() while my UDF is using it still?

do i need to test for TCP status at the beginning of each function in my UDF, so i can start it if it isn't started yet? that seems too inelegant.

ideas?

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

For a UDF, TCPStartUp() is the including script's responsibility (like caling _GDIPlus_Startup() or _SQLite_Startup() prior to using functions from a UDF that depend on these libraries). Check in each function helps debugging (uninitialized use will error eventually, a check at least identifies the cause), but TCP functions return @error WSANOTINITIALISED (10093) if called prior to TCPStartup() already.

Generally speaking, anything of global effect is the script's (not UDF's) responsibility (code becomes inflexible/unmanageable otherwise). Of course you can do as you please (it's a convenience vs. flexibility trade off eventually).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...